Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 22nd, 2008, 11:47 PM   #1
King
Professional Programmer
 
King's Avatar
 
Join Date: Jan 2006
Location: Ontario, Canada
Posts: 364
Rep Power: 0 King is an unknown quantity at this point
Question Threading

When do you guys use multi-threading in your windows applications in C#? I know how to use the different threading libraries in C#, but never find good situations to use them that a timer control can't take care of. So I was just wondering what situations you guys use multi-threading in?
__________________
I am Addicted to Linux!
King is offline   Reply With Quote
Old Mar 23rd, 2008, 1:42 AM   #2
crawforddavid2006
Expert Programmer
 
crawforddavid2006's Avatar
 
Join Date: Apr 2005
Location: Not sure yet
Posts: 569
Rep Power: 0 crawforddavid2006 is an unknown quantity at this point
Send a message via AIM to crawforddavid2006 Send a message via MSN to crawforddavid2006
Re: Threading

I've never had to use multi-threading.
__________________
Quote:
Originally Posted by DaWei View Post
Well, it's better than Pen Islands url....;)

crawforddavid2006 is offline   Reply With Quote
Old Mar 23rd, 2008, 3:47 AM   #3
big_k105
PFO Founder

 
big_k105's Avatar
 
Join Date: Mar 2004
Location: Fargo, ND
Posts: 1,613
Rep Power: 10 big_k105 is on a distinguished road
Send a message via AIM to big_k105 Send a message via MSN to big_k105 Send a message via Yahoo to big_k105
Re: Threading

I used multi-threading on a program that I wrote that read information for a external scale and had to do a count of the number of items on the scale. The reason I used it was so the window wasn't froze and could still close the window after they were done dumping parts on the scale. Since there was no way to know when the user would stopped putting items on the scale, so it would constantly read from the scale until the user closed the window and then the thread would be killed.

Hope that makes sense
__________________
BIG K aka Kyle
Programming Forums
Kyle K Online

Please do not PM or email me programming questions. Post them in the forums instead.
big_k105 is offline   Reply With Quote
Old Mar 23rd, 2008, 9:18 AM   #4
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
Re: Threading

I've used timers to reset the color of a button after some time without freezing the window so that I can still accept user input while waiting for the color to reset. I don't know if that counts as multi-threading...
OpenLoop is offline   Reply With Quote
Old Mar 23rd, 2008, 11:19 AM   #5
King
Professional Programmer
 
King's Avatar
 
Join Date: Jan 2006
Location: Ontario, Canada
Posts: 364
Rep Power: 0 King is an unknown quantity at this point
Re: Threading

Big K - That makes perfect sense.

OpenLoop - That does count as multi-threading, but I was referring more to the actual Thread class in C#. I have used the timer control numerous times (can be quite handy).

The reason I ask for places to use it is that I have a fairly big application that uses a lot of the different advanced features of C# and would be good to showcase to potential employers, and I wanted a good reason to use the thread class. I have come across a few good places to uses them, but it turns out there is always a better, more simple way to achieve that task without threading.
__________________
I am Addicted to Linux!
King is offline   Reply With Quote
Old Mar 23rd, 2008, 2:16 PM   #6
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 730
Rep Power: 4 Dameon is on a distinguished road
Re: Threading

The timer control isn't actually 'multithreading.' The OS posts a message to the message loop on the main thread at the specified interval. Only one thread actually exists. The timer going off is entirely dependent on your main thread returning to the message loop and checking for messages. (Form/control events are raised by the message loop in response to window messages. The reason the form will 'freeze up' when you put something time consuming in an event handler is because it can't check for messages until the handler returns).

The other timer classes (such as in System.Threading) actually spawn a background thread which sleeps until it is supposed to go off. This will work regardless of if your main thread is busy, but you then have to deal with the issues associated with multiple threads.


Sometimes it makes sense to do more than one thing at once. Perhaps you have an algorithm that needs to take advantage of multiple cores/processors. Or perhaps you have a single processor system, but want to use the processor as effectively as you can. Just as one running program will take advantage of another running program sleeping, using multiple threads lets the OS scheduler give you time where you would otherwise not have any. Say you are reading and processing a large file. Reading from file is a time consuming operation. You don't know how busy the disk is or how far it has to seek. Your request might be at the end of a rather long queue. Even in the best case, we're talking milliseconds. A millisecond is a long time. With a single thread, while you're waiting on data from the hard drive, you can't process any data. And while you're processing data, you can't queue any read requests, so the disk may well spin idle. Say you have two threads, one which reads the file in some kind of logical chunks and posts the each chunk to a shared queue, and another which does processing chunk by chunk, grabbing each chunk from the shared queue. And perhaps you have a 3rd thread handling the user interface. Every 50th chunk, the processing thread posts a message to update a progress bar. But the rest of the interface code can be written as if the background operations don't even exist.
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270
Dameon is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
C# Threading Resource Dameon C# 4 Jun 23rd, 2007 2:39 PM
Threading with Hashtable class ssrun Java 1 Mar 23rd, 2007 6:41 PM
.NET threading & memory hbe02 Other Programming Languages 0 Sep 28th, 2006 6:53 AM
Threading + Progress tayspen C# 9 Dec 16th, 2005 11:50 AM
help on threading lucifer C# 4 Dec 2nd, 2005 2:48 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:41 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC