How do I stop a thread?

Showing Answers 1 - 3 of 3 Answers

krishnasharana

  • Oct 20th, 2005
 

.NET allows to call System.Windows.Forms.Control functions only from thread where control was created. To run them from other thread we need to use Control.Invoke (synchronous call) or Control.BeginInvoke (asynchronous call) functions. For task like showing database records we need Invoke. To implement this :Delegate type for calling form function, delegate instance and function called using this delegate Invoke call from worker thread. Next problem is to stop worker thread correctly. Steps to do this:Set event "Stop Thread" Wait for event "Thread is stopped" While waiting for event process messages using Application.DoEvents function. This prevents deadlock because worker thread makes Invoke calls which are processed in main thread. Thread function checks in every iteration whether Stop Thread event is set. If event is set, function makes clean-up operations, sets event "Thread is stopped" and returns.

  Was this answer useful?  Yes

sabir

  • Jan 13th, 2006
 

treadname.abort ''''' to stop the thread and treadname.stop '''' t

  Was this answer useful?  Yes

dotnetrocks

  • Jun 7th, 2006
 

thread can be stopped temporarily by thread.suspend and then recovered by thread.resume. Also thread.abort stops the thread completely and cannot be recovred unless created a new one.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions