Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Orchestrate an Efficient .NET Network Using the WMI Event Model  : Page 4

Learn how WMI events can help your .NET applications listen in on a vast array of system activities and even take advantage of spare capacity.


advertisement
Putting It All Together
Whether you piece it together by hand, or cheat with the WMI tools, writing the WQL query is 90 percent of the work involved with subscribing to an event. To use your query, just construct an instance of the ManagementEventWatcher class with the query text as an argument. Finally, subscribe to the event called EventArrived, like this:

idleWatcher = new ManagementEventWatcher(queryString); idleWatcher.EventArrived += new EventArrivedEventHandler(OnIdle); idleWatcher.Start();

The instances of ManagementEventWatcher are often called "temporary event consumers" because they last for (at most) the lifetime of the application. For a more permanent notification, you can set up an alert through the Windows Performance Monitor (perfmon.exe). Listing 2 shows the complete code for the ProcessorIdleWatcher.

Wrapping It Up
Next year's release of Visual Studio 2005 will include so many changes that I'm hesitant about investing too much time learning unfamiliar areas of .NET 1.1. The good news is that time spent learning WMI won't be wasted because the technology is standardized, widely used, and independent of its .NET implementation. The wrapper classes may change, but WMI isn't going away.



Of course, WMI has much a much broader set of applications than just background processing. You can listen for new USB devices or runaway processes. But whatever events your application needs to know about, the subscription process is exactly the same.



Eric McMullen is a director at Falstaff Solutions, a Denver-based consulting house which specializes in data-centric .NET applications. Check out Falstaff's Web site at www.falstaffsolutions.com.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date