The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Should You Call Thread.Abort?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Doug Thews

Posts: 866
Nickname: dougthews
Registered: Jul, 2003

Doug Thews is a software developer/manager for D&D Consulting Services with 18+ years of experience
Should You Call Thread.Abort? Posted: Oct 10, 2004 2:48 PM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Doug Thews.
Original Post: Should You Call Thread.Abort?
Feed Title: IlluminatiLand
Feed URL: http://apps5.oingo.com/apps/domainpark/domainpark.cgi?client=netw8744&s=JETBRAINS.COM
Feed Description: A technology blog for people enlightened enough to think for themselves
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Doug Thews
Latest Posts From IlluminatiLand

Advertisement

There's a lot of mis-information about how to cancel a worker thread. A lot of articles (including some MSDN documentation) shows calling Thread.Abort() in the main thread, followed by a Thread.Join() call to block the thread until the worker thread ends. Then, in the worker thread, you wrap your entire code section with Try...Catch and catch the ThreadAbortedException.

However, some C# MVPs in the Microsoft news group have told me that this may actually lead to the crash of your AppDomain, or at minimum cause instability within your application.

Instead, they recommend using Thread.Interrupt() to generate a "soft" interrupt in your worker thread, and handle the ThreadInterruptedException instead of the ThreadAbortedException to gracefully exit from the worker thread.

One thing is for sure ... you need to make sure to do all of your worker thread cleanup within this exception handling code. if you don't, there's a chance that your thread could stay active and resident. You can use Task Manager (and add Thread Count to the column view) to see if your application is still resident after you think you've closed it. Thread Count is a very useful value to determine how many threads your application actually has active at any given point in time.

Read: Should You Call Thread.Abort?

Topic: FabriKam - The Microsoft Office System Solutions Learning Platform Previous Topic   Next Topic Topic: A Bloggers Guide to BizTalk

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use