WMI EventArrivedEventHandler :: UI problems

  • Thread starter Thread starter Crile Carvey
  • Start date Start date
C

Crile Carvey

I have created a ManagementEventWatcher and a corresponding
EventArrivedEventHandler. The basics work fine - when a USB device is
inserted or removed, the EventArrivedEventHandler fires successfully.

However, any references to UI objects on the form fail without any error
messages. When walking through the code in the debugger, the lines are
seemingly ignored.

Any help appreciated.

Crile


Please refer to the following snippet:

q = new WqlEventQuery();
q.EventClassName = "__InstanceCreationEvent";
q.WithinInterval = new TimeSpan(0, 0, 3);
q.Condition = @"TargetInstance ISA 'Win32_USBControllerdevice'";
w = new ManagementEventWatcher(scope, q);
w.EventArrived += new EventArrivedEventHandler( USBInserted);
w.Start();//run the watcher

public void USBInserted(object sender, EventArgs e) {
// Debugger gets to here but following line is apparently ignored
this.listBox1.Items.Add("Inserted: " + DateTime.Now.ToString());
}
 
Heya!

I have a similar problem to you and, likewise, I am starting to think it's a cross-threading problem.

Please could you post your solution here?

Cheers

Matthew



CrileCarve wrote:

RE: WMI EventArrivedEventHandler :: UI problems
20-Feb-08

Got it - it was a cross-threading issue

:

EggHeadCafe - Software Developer Portal of Choice
Use IDENT_CURRENT to retrieve the last inserted value into the Identity column
http://www.eggheadcafe.com/tutorial...96-0f6c2138e101/use-identcurrent-to-retr.aspx
 
Back
Top