Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
Hi,

In my winform application, I use two timers both having different functionality, but one of it is copying one file (big file) and save it to another folder. Another showing me the time on my application

But the problem is when file is copy from one location to another than application become hanging.

The solution I get here is that I have to use threading in which one timer is in one thread and another timer is in another thread.

Can You Tell Me How This Happens (by giving a snippet of multiple threading of any example so that i can understand how to use it)......


Thanks In Advance A Lot.....
Posted
Comments
Sergey Alexandrovich Kryukov 7-Apr-14 10:42am    
Not enough information. It could be a deadlock, but not only that.
—SA
binadi007 7-Apr-14 10:46am    
What You Want To Know @Sergey
phil.o 7-Apr-14 11:25am    
Please show the code you have so far, especially the methods that execute as your Timers tick.
And please put it in your question (use the 'Improve' button), not in a comment ;)

1 solution

1.First you don't need to use timers mixed with threads, because the timer event is automatically executed into a separate thread.

2.Maybe your problem is created by the fact, that your timer interval (maybe some seconds) is match shorter then the time needed to copy your big file, so your timer event will be fired more then one time for the same file.

3.The solution is to use some flag variable like: bool isCopyingFile = false; and to set this variable on true when you start to copy the file, then to use a try-finally block and in finally to set back the flag on false. And before to start the new copy to check this flag and if is true to wait until the current file is copying (by using a simple if and return). Then do not forgot to release the streams used for accessing and copying the file.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900