Microsoft is correct (no disrespect Dan - I presented on Multithreading tonight and gave away your book. I will email you my slides). Aborting a thread should be avoided for a number of reasons.
From
Juval Lowey, one of my favorite authors, See:
http://www.baynetug.org/uploads/Productive%20.NET%20with%20Juval%20Lowy%20.pdf
Killing a Thread
------------------
Do not call Abort()
Thread may need to do clean-up
Abort() does not allow graceful exit
The thread method should check a flag
Protect flag with mutex
Kill() method should set flag and wait for thread to terminate
Abort() has another flaw: Thread can do indefinite processing in catch{} Application
public class WorkerThread : IDisposable
{
protected Thread m_ThreadObj;
protected bool m_EndLoop;
protected Mutex m_EndLoopMutex;
protected bool EndLoop
{
set
{
m_EndLoopMutex.WaitOne();
m_EndLoop = value;
m_EndLoopMutex.ReleaseMutex();
}
get
{
bool result = false;
m_EndLoopMutex.WaitOne();
result = m_EndLoop;
m_EndLoopMutex.ReleaseMutex();
return result;
}
}
public WorkerThread()
{
m_EndLoop = false;
m_ThreadObj = null;
m_EndLoopMutex = new Mutex();
}
Kind Regards,
Damon Wilder Carr, Chief Technologist and CEO
.NET SIG Leader - New York Software Industry Association (NYSIA www.nysia.org)
Founder and President: 'Association for the Advancement of Software Engineering in .NET' (AASET)
Microsoft Certified Partner
Visual Studio Industry Partner Affiliate
Professional Member - Association for Computing Machinery (
www.acm.org)
agilefactor
80 Broad Street
5th Floor
New York, NY 10004
Voice 212.837.7788
Fax 212.859.7359
http://www.agilefactor.com/
http://agiledamon.blogspot.com/