Stopping a thread in .Net Framework

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


Ani Leeye
Views: 2785 | Community Opinion: 4

Tags..  .Net Framework Threading  .Net Framework  .Net threads

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.




Igyotbdj Said..

Thanks!,




schoooler Said..

Hi, i'm schoooler

I’m new to the forum and just saying hello.




tttt Said..

good






Register or Login to Post Your Opinion