user677526
user677526

Reputation:

Is Thread.Abort() ever called by the .NET runtime?

I've inherited some service code and I'm trying to track down an issue with service crashes. I've found the following code in many places:

catch (ThreadAbortException)
{
    throw;
}

However, I can't find any calls to Thread.Abort() or Thread.Kill() in any parts of the project (or related projects).

Is Thread.Abort() ever implicitly called by the .NET runtime, or does that exception exist only to catch calls that a developer makes? I'm trying to narrow my error avenues and I'm not very experienced with threads in C#. I'm trying to determine whether the catch block I've shown is ever actually hit if Thread.Abort() is never actually called in my codebase.

Thanks!

Edit: I want to clarify - I know that .NET can kill threads, but I was wondering if it specifically calls Thread.Abort() or whether it uses some other means (as the ThreadAbortException is only called on Thread.Abort().

Upvotes: 3

Views: 303

Answers (2)

noseratio
noseratio

Reputation: 61744

Edit: I want to clarify - I know that .NET can kill threads, but I was wondering if it specifically calls Thread.Abort() or whether it uses some other means (as the ThreadAbortException is only called on Thread.Abort().

If you're really interested to see whether (and where) it does that, refer to .NET Reference Source, it's pretty complete. Specifically, it shows that Thread.Abort is referenced at these places.

Upvotes: 0

MatthewMartin
MatthewMartin

Reputation: 33183

Catch/throw without doing anything about it seems pointless.

These errors are common in ASP.NET-- it means a redirect that ended the response, eg. ASP.NET Response.Redirect( ) Error

or it means a worker process was killed by casinni/iis/aspnet for it's own mysterious reasons, maybe worker process recycles, etc.

It normally doesn't indicate a programming error.

Calling Thread.Abort() in multi-threaded apps appears to be a bad idea in most cases and other answers on SO speak to that better than I could.

Upvotes: 2

Related Questions