Multithreaded App Stops Working

grip003

Regular
Joined
Sep 2, 2004
Messages
89
Location
North Carolina
I have written a backup utility that simply copies certain files from one location to another on my computer. I used multithreading to handle the file copying so that I could let it run in the background while I am still working on things. The problem I am running into is that for some reason the application seems to just stop randomly some amount of time into the file copy. I also wrote a version of this software to automatically burn CD backups, and the same thing is happening. I decided to try one of my other multithreaded apps, and it also stopped in the middle of progress. These problems started occurring when I moved to a new dual-core machine. The programs seem to work fine on a single core/single processor machine. Can anyone tell me what might be wrong? Am I just not programming the multithreading correctly?
 
Without seeing any code it is pretty difficult to pinpoint the problem. Be aware that writing correct multi-threaded code is not a trivial task as you often need to co-ordinate the multiple threads to prevent deadlocks and race conditions occuring.

Any multi-cpu machine is more likely to reveal any potential issues as it is then actually running multiple threads concurrently.
 
The only resource being shared by the threads is the GUI, basically just a progress bar and a label being updated. Do you think that might be the cause of the problem?
 
If you are directly using the GUI from the separate threads, yes that can cause a lookup. GUI related stuff should be done on the thread that created the GUI components.
That sounds harder than it is, you can use <control>.InvokeRequired to see if you are on the correct thread, and <control>.Invoke to send the command to the GUI thread if you are not. Search this forum for InvokeRequired, you'll find several examples like this: http://www.xtremedotnettalk.com/showthread.php?t=86818&highlight=InvokeRequired
 
Thanks Wile, I will start looking through my code and try using the InvokeRequired stuff. I'll repost in a little while to let you know how things worked.
 
Back
Top