Editorials

Dot Net ThreadPool and Timers

SSWUGtv
With Stephen Wynkoop
In this edition Steve talks with Laura Rose about "How do you maintain confidence in your job when your boss leaves the company".
Watch the Show

Dot Net ThreadPool and Timers
I have been playing with the System.Threading.Timer object in Dot Net for a couple days now. Historically I have used timers in forms, so I don’t have much opportunity to use timers at all.

The neat thing about the System.Threading.Timer object is the fact that it integrates with the Dot Net ThreadPool. You can establish a timer with a delay state, and while the timer is in the delay mode, it will not take up any CPU resources.

I tried an example that used two timers, and each one, when it fired would print the ThreadID. Both timers, if they didn’t fire at the same time, had the same ThreadID. If they fired simultaneously, they had two different ThreadIDs.

I found this a useful way to create timers and not fire up a thread for each one of them. Instead, they operate based off the thread pool and utilize it for performing work when the timer fires.

There’s a simple example you can find at http://csharptips.wordpress.com/tag/system-threading-timer.

Reader Feedback

Asher shares with us a great example of multi-thread programming, and why it can be useful in your applications.

I’d like to share my experience.

I developed a multithreaded application in c++.

One thread was drawing rectangles of different sizes on the Monitor screen.
A second thread collected data while a patient would watch the Monitor.
A third thread analyzed the collected data.
A fourth thread drew graphs according to the results of the analysis.

All four threads were running in parallel.

Running this program on 3.3 GHz processor machine with a single core, it was pausing while drawing graphs and rectangles.

But, when we use a dual core processor, the same program worked perfectly.

Share your thoughts and experiences on threading or any other topic by writing to btaylor@sswug.org.

Cheers,

Ben

$$SWYNK$$

Featured White Paper(s)
Encryption & Key Management for Microsoft SQL Server 2008/2012
Simplify encryption and key management on your SQL Server. Data thieves are targeting SMB companies because of their inadequa… (read more)

Featured Script
Check free space on drive
this routine will check free space on your server as well as on all linked servers and send an email-requires sqlMail… (read more)