Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

Can anybody tell me how to ensure that the worker thread or the background thread which is running from the main thread completes its task or not. I have a thread through which i am polling certain devices along with this i want to update the UI thread & also save the data to database. I want to ensure that all the tasks are completed by the worker thread & then run UI thread continuously. Like run UI thread for polling wait for worker thread to finish its task & continue to poll.

Thanks in advance.
Posted
Comments
Sunasara Imdadhusen 6-Jun-13 2:19am    
Have you started anything for the same?
Member 4484632 6-Jun-13 2:30am    
Hi,
Use backgroundWorker in the form.
in the backgroud_dowork event call your code and update progress bar until it will finished.

Thanks
Pramod.K

1 solution

You can either wait for it or abort it (and then wait anyway). Please see:

Waiting for:
http://msdn.microsoft.com/en-us/library/95hbf2ta.aspx[^],
http://msdn.microsoft.com/en-us/library/6b1kkss0.aspx[^],
http://msdn.microsoft.com/en-us/library/23f7b1ct.aspx[^].

Aborting:
http://msdn.microsoft.com/en-us/library/ty8d3wta.aspx[^],
http://msdn.microsoft.com/en-us/library/5b50fdsz.aspx[^].

Many think that abortion is dangerous and hence unacceptable, but this is not true, only if you know very well what you are doing. Abort has nothing to do with ungraceful TerminateThread, and the objections are often based on it, without understanding how it works. This is very non-trivial mechanism. It tried to explain it in my past answers:
Close correcly the thread inside a dll[^],
Problem with creating Process from dedicated thread[^].

—SA
 
Share this answer
 
Comments
tumbledDown2earth 6-Jun-13 2:31am    
Great answer.. my 5
Sergey Alexandrovich Kryukov 6-Jun-13 2:36am    
Thank you very much.
—SA

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