Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
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?
  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted
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?
Posted

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

Nothing is as illusive as 'the last bug'.
  • 2 weeks later...
Posted
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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...