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 2

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
Figure 1. The SlowTextBox: This image shows the SlowTextBox in the process of initialization.

The Sample Project: Introducing WIC
To show you how to subscribe to WMI events through .NET, this sample project (\WMIEvents.zip) kicks off a time-consuming operation on a new thread. Pretty standard stuff, really, but the difference here is that the operation starts only if there's enough spare processing power to make it worthwhile. It's a lot like spinning off a low-priority thread for background processing, but this approach gives the programmer far more control over the circumstances.

To simulate a time-consuming task, I built a class called SlowTextBox. Just like it sounds, the control inherits from System.Windows.Forms.TextBox, but this particular implementation has to be initialized for a fixed period of time prior to use. The idea is to simulate some kind of long operation—like getting lots data from a database or talking to a Web service. Once the SlowTextBox is initialized, it works just like a standard TextBox.



Listing 1 shows the complete code for the SlowTextBox.

The project contains three tabs, each with its own instance of SlowTextBox, and each with its own initialization philosophy. The first two approaches should look familiar. The "Naïve" tab just initializes on startup. In this case, "naïve" just means the simplest possible approach of initializing at application startup; it doesn't imply any kind of value judgment. The next tab is called JIT—for "Just In Time." This approach puts off initialization until the user actually clicks the tab.

Not until the final tab do you need WMI. The idea here is that many applications—GUI applications, especially—spend most of their time just waiting for user input, so why not use that time for background processing? That way, the application looks faster to the user. I call the approach "When It's Convenient," or WIC. The following table outlines the thee approaches.

Table 1 The three approaches to initialization.

Approach

Description

Used for

Naïve

Initializes on application startup.

Critical or very fast operations.

JIT

Initializes when the resource is actually needed.

Non-critical and potentially time-consuming operations.

WIC

Initializes when the system load gets low.

Non-critical operations that can run on a separate thread.



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