GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Microsoft  >  Basics
Go To First  |  Previous Question  |  Next Question 
 Basics  |  Question 28 of 42    Print  
How do I stop a thread?

  
Total Answers and Comments: 3 Last Update: June 08, 2006     Asked by: Srikanth 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: dotnetrocks
 
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.

Above answer was rated as good by the following members:
chintan.desai
October 20, 2005 02:16:37   #1  
krishnasharana        

RE: How do I stop a thread?
.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.
 
Is this answer useful? Yes | No
January 13, 2006 08:34:17   #2  
sabir        

RE: How do I stop a thread?
treadname.abort ''''' to stop the thread and treadname.stop '''' t
 
Is this answer useful? Yes | No
June 07, 2006 15:46:38   #3  
dotnetrocks        

RE: How do I stop a thread?
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.
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape