[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

RaiseEvent Not Firing

Posted on 2007-08-01
10
Medium Priority
?
1,889 Views
Last Modified: 2013-11-07
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
0
Comment
Question by:StaceyBerry
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 13

Expert Comment

by:Corey Scheich
ID: 19612601
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.
0
 
LVL 9

Expert Comment

by:JonMny
ID: 19632301
doesnt look like you ever create the object

  Me.moStatusFileWatcher = New StatusFileWatcher
0
 

Author Comment

by:StaceyBerry
ID: 19640504
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?
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
LVL 9

Expert Comment

by:JonMny
ID: 19640593
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

0
 

Author Comment

by:StaceyBerry
ID: 19641121
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!
0
 
LVL 13

Expert Comment

by:Corey Scheich
ID: 19647321
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.
0
 
LVL 13

Accepted Solution

by:
Corey Scheich earned 2000 total points
ID: 19683528
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
0
 
LVL 1

Expert Comment

by:Computer101
ID: 20633895
Forced accept.

Computer101
EE Admin
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Make the most of your online learning experience.
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question