Thought for the Dazed

I've had to give up that Distance Learning course as I was having trouble seeing the teacher.

Flickr
www.flickr.com
RobMiles' items Go to RobMiles' photostream
Twitter
C# Yellow Book

Search entire site
« PDF Output from Vista | Main | Early Bird »
Tuesday
Apr172007

Threading with Forms

Some of our students have been having fun with threading and forms (there is a lab out there at the moment which can be solved by creating a thread which performs a task).

Threads are great, because you can send them off to do something while you get back to responding to the user, or whatever. Snag is, when another thread tries to dicker with the contents of a form this ends in tears, as the Windows system is very picky about actions like this. There is a way round the problem though, and so I've written a little sample application which shows you how to do it.

It creates a form which has a single button on it. When you press the button it creates a worker thread and fires it off in another class to do something. When the something finishes it then calls back into the form to change the text in a label on that form. You can use this as a model for whatever you fancy doing with threads. You can find the code here.

Reader Comments (1)

This is an another link to a good example on Worker Thread
http://www.codeproject.com/cs/threads/workqueuethreading.asp
April 19, 2007 | Unregistered CommenterAnkur Gurha

PostPost a New Comment

Enter your information below to add a new comment.
Author Email (optional):
Author URL (optional):
Post:
 
All HTML will be escaped. Hyperlinks will be created for URLs automatically.