Click here to Skip to main content
15,887,596 members
Home / Discussions / C#
   

C#

 
GeneralRe: resource leak in thread termination? Pin
Guffa28-Apr-08 14:31
Guffa28-Apr-08 14:31 
GeneralRe: resource leak in thread termination? Pin
George_George29-Apr-08 2:41
George_George29-Apr-08 2:41 
GeneralRe: resource leak in thread termination? Pin
Guffa29-Apr-08 8:37
Guffa29-Apr-08 8:37 
GeneralRe: resource leak in thread termination? Pin
George_George29-Apr-08 21:50
George_George29-Apr-08 21:50 
Generalstop a thread Pin
George_George21-Apr-08 23:49
George_George21-Apr-08 23:49 
GeneralRe: stop a thread Pin
Mircea Puiu22-Apr-08 1:12
Mircea Puiu22-Apr-08 1:12 
GeneralRe: stop a thread Pin
George_George22-Apr-08 1:14
George_George22-Apr-08 1:14 
GeneralRe: stop a thread Pin
Mircea Puiu22-Apr-08 1:42
Mircea Puiu22-Apr-08 1:42 
A blocked thread can be released prematurely in one of two ways:
- through Thread.Interrupt;
- through Thread.Abort.

1) This will happen through the activity of another thread.
Interrupting a thread only releases it from its current/next) wait.
It doesn't cause the thread to end (unless the ThreadInterruptedException is unhandled).
If Interrupt is called on a thread that’s not blocked, the thread continues executing until it next blocks. At that point a ThreadInterruptedException is thrown.
Interrupting a thread arbitrarily is dangerous as the framework or some third-party methods in the calling stack could unexpectedly receive the interrupt rather than your intended code. All it would take is for the thread to block briefly on a simple lock or synchronization resource, and any pending interruption would kick in. If the method wasn't designed to be interrupted (with appropriate cleanup code in finally blocks) some objects may be left in an unusable state, or there may be resources incompletely released.

2) A blocked thread can also be released via its Abort method. This would lead to a similar effect like in the case of calling Interrupt, excepting that a ThreadAbortException is thrown instead of a ThreadInterruptedException. And one more thing here: the exception will be re-thrown at the end of the catch block (in an attempt to terminate the thread for ever) unless Thread.ResetAbort is called within the catch block.

The main difference between Interrupt and Abort concerns what happens when each of them is called on a thread that is not blocked. While Interrupt waits until the thread next blocks before doing anything, Abort throws an exception on the thread right where it's executing.

SkyWalker

GeneralRe: stop a thread Pin
George_George22-Apr-08 2:53
George_George22-Apr-08 2:53 
GeneralRe: stop a thread Pin
Mircea Puiu22-Apr-08 5:04
Mircea Puiu22-Apr-08 5:04 
GeneralRe: stop a thread Pin
George_George22-Apr-08 16:25
George_George22-Apr-08 16:25 
GeneralRe: stop a thread Pin
Mircea Puiu23-Apr-08 20:52
Mircea Puiu23-Apr-08 20:52 
GeneralRe: stop a thread Pin
George_George23-Apr-08 21:00
George_George23-Apr-08 21:00 
GeneralRe: stop a thread Pin
Mircea Puiu24-Apr-08 20:43
Mircea Puiu24-Apr-08 20:43 
GeneralRe: stop a thread Pin
George_George24-Apr-08 21:34
George_George24-Apr-08 21:34 
GeneralRe: stop a thread Pin
Ravi Bhavnani22-Apr-08 2:16
professionalRavi Bhavnani22-Apr-08 2:16 
GeneralRe: stop a thread Pin
George_George22-Apr-08 3:01
George_George22-Apr-08 3:01 
GeneralRe: stop a thread Pin
Ravi Bhavnani22-Apr-08 4:57
professionalRavi Bhavnani22-Apr-08 4:57 
GeneralRe: stop a thread Pin
George_George22-Apr-08 16:23
George_George22-Apr-08 16:23 
QuestionC# Drawing question Pin
oliversimon21-Apr-08 23:12
oliversimon21-Apr-08 23:12 
GeneralRe: C# Drawing question Pin
Reelix22-Apr-08 0:09
Reelix22-Apr-08 0:09 
GeneralRe: C# Drawing question Pin
oliversimon22-Apr-08 0:34
oliversimon22-Apr-08 0:34 
GeneralRe: C# Drawing question Pin
Anthony Mushrow22-Apr-08 1:35
professionalAnthony Mushrow22-Apr-08 1:35 
GeneralRe: C# Drawing question Pin
Reelix22-Apr-08 1:55
Reelix22-Apr-08 1:55 
GeneralRe: C# Drawing question Pin
Anthony Mushrow22-Apr-08 2:00
professionalAnthony Mushrow22-Apr-08 2:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.