grip003 Posted June 27, 2006 Posted June 27, 2006 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? Quote
Administrators PlausiblyDamp Posted June 27, 2006 Administrators Posted June 27, 2006 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
grip003 Posted June 27, 2006 Author Posted June 27, 2006 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? Quote
Wile Posted June 28, 2006 Posted June 28, 2006 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 Quote Nothing is as illusive as 'the last bug'.
grip003 Posted July 6, 2006 Author Posted July 6, 2006 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.