Stopping a thread in .Net Framework

How do I stop a thread in .Net Framework in C#, or VB.NET?

Tags..  .Net Framework Threading  .Net Framework  .Net threads
Posted by: Ani Leeye | Views: 704 | Community Opinion: 1

Add Your Opinion

Bookmark this page..



Ask a New Question Go to Home


Community Opinion/Answers
Vinkar said..

There are several options available in .Net Framework to stopt the thread First, you can use your own communication mechanism to tell the ThreadStart method to finish. Alternatively the Thread class has in-built support for instructing the thread to stop. The two principle methods are Thread.Interrupt() and Thread.Abort(). The former will cause a ThreadInterruptedException to be thrown on the thread when it next goes into a WaitJoinSleep state. In other words, Thread.Interrupt is a polite way of asking the thread to stop when it is no longer doing any useful work.

In contrast, Thread.Abort() throws a ThreadAbortException regardless of what the thread is doing. Furthermore, the ThreadAbortException cannot normally be caught (though the ThreadStart's finally method will be executed). Thread.Abort() is a heavy-handed mechanism which should not normally be required.



What do you think? Add your opinion/answer
Your Name:
*your opinion/answer: