RaiseEvent Not Firing

I am developing in VB.NET and trying to raise an event that will notify my form when a status changes behind the scenes in the file directory.  The code hits the RaiseEvent statement but never raises the event and processes the code I have associated with it. I have attached a sample below...

Public Class StatusFileWatcher
    Public Event WatchdogStatusChange()

    Private Sub CompareNewToOld()
        ' Some looping and comparisons are going on here in the beginning
         'andt in the middle of the sub the raise event is hit, but not fired
 If strName = "Watchdog:" And (cntrlGroupBox.Controls(intGroupChild).Text <> statusFieldNode.InnerText.ToString) Then
        RaiseEvent WatchdogStatusChange()

 End If
 End Sub
'Here is the Form code...

Public Class frmOMARFileManager

    Private WithEvents moStatusFileWatcher As StatusFileWatcher

    Public Sub moStatus_WatchdogStatusChange() Handles moStatusFileWatcher.WatchdogStatusChange
        MessageBox.Show("Watchdog Status Change: ")
    End Sub
Who is Participating?
Corey ScheichConnect With a Mentor DeveloperCommented:
Another possibility is to have the object passed in the sub new of the second form.

Public Sub New (byval FileWatcherObj as FileWatcher)
AddHandler FileWatcherObj.WatchdogStatusChange,AddressOf moStatus_WatchdogStatusChange
end sub
Corey ScheichDeveloperCommented:
First two things I would look at.

Make sure the object calling the event is infact the object being watched.  If you re-assign the variable to a new object sometimes you loose the events because they were being handled for the old object.

Add an Application.DoEvents  after the event this will ensure that all events that were raised will be handled before continuing the code.
doesnt look like you ever create the object

  Me.moStatusFileWatcher = New StatusFileWatcher
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

StaceyBerryAuthor Commented:
Even with the above advice the raise event is still not firing.  It appears to be some sort of ownership problem between the two forms?
If it's getting to the raise event and not firing it must not have the events wired for some reason. try manually attaching the event.
in form load...

AddHandler moStatusFileWatcher.WatchdogStatusChange,AddressOf moStatus_WatchdogStatusChange

StaceyBerryAuthor Commented:
Still no luck.  It starts screaming about loading the form and circular references...although I'm almost certain there are none.  Somthing's buggy.

I'll have to look for an alternate method.  Thanks!
Corey ScheichDeveloperCommented:
How about having your main form raise an event for this from the event catch on the main form and having a parent form object on your child form that is set to the main form and being watched.  SHeesh it seems I could have worded that better.
Forced accept.

EE Admin
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.