Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 916631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:04:56+00:00 2026-05-15T18:04:56+00:00

I understand that calling Thread.Abort() is BAD AND WRONG because of various reasons Can

  • 0

I understand that calling Thread.Abort() is BAD AND WRONG because of various reasons

  1. Can be locking or in other critical region
  2. Could be midway through an I/O operation, resource won’t get cleaned up
  3. Code can swallow ThreadAbortException
  4. Could be midway through a state change operation, and leave the program in an invalid state.

Assuming that the thread’s Run() method:

  1. Does not use concurrency primitives.
  2. Does not perform any I/O.
  3. Does not swallow such exceptions.
  4. Is exposed to a read-only API, so cannot change program state.

Question:

If I were to call Abort() on such a thread, is the damage done (with regards to corruption) localized? As in, can I rely on my program, sans the recently aborted thread, to continue to behave normally, or is my entire process/AppDomain/?? then potentially corrupted?

If I remove assumptions 1 and 2 would abort() corruption be localized to the specific concurrency primitives and i/o resources it accessed? Or can it propogate outwards?

Why am I flogging the Thread.Abort() dead horse:

I’m writing a thick client c# winforms application. One feature s the ability for the user to write code in c# which implements interfaces on my domain objects which can then be plugged into my application (code is compiled into an assembly via codedom and loaded using reflection);

So the idea is the user could then write

public class CustomComputation : IComputationThing
{
    public void Compute(object context)
    {
        while (true) ;
    }
}

and I could then reflect on the generated assembly, extract and instantiate an instance of CustomComputation, and call Compute(...); Pretty straightforward stuff.

The problem is that the user could then write, well, the above – an infinite loop, or some other exponential time computation he decides he doesn’t want to wait for.

I am trying to investigate my options for providing a best-effort recovery for when users write some infinite-looping (or exponential time etc) code and wants to abort from that. While I do intend to ask users to adhere to a cancellation pattern but ultimately there is no guarantee that they will.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T18:04:57+00:00Added an answer on May 15, 2026 at 6:04 pm

    As mentioned by Vilx- you could consider putting the "user" code in another AppDomain.

    In fact, since .Net 3.5, the .Net Framework has included the System.AddIn namespace, which provides a simplified way of isolating "add-in" code in seperate app domains (amongst other things). Provided there isn’t too much cross-domain communication required, this gives you a nice level of isolation whereby the worst case scenario is that you tear down an AppDomain that is specific to the user code.

    See this MSDN article and the CLR-Addin team’s blog for more information.

    Additionally, although it doesn’t solve everything, you could start by firing a Thread.Interrupt. This will cause a ThreadInterruptException to be raised in a similar way to ThreadAbortException, except that it will occur oinly at defined points in the code; when the thread blocks or sleeps, rather than absolutely anywhere. It probably won’t help in the tight-loop example you mention above, but would if the loop had a Thread.Sleep(0).

    You can always graduate your options:

    • Put a Stop() method on IComputationThing and ask users to implement it.
    • If an add-in doesn’t respond to Stop() in a timely fashion, try a Thread.Interrupt (and document that tight-loopers might want to put a Thread.Sleep(0) in their loops to yield to another thread)
    • If that fails, try the Thread.Abort, or tear down the App Domain (probably the latter directly).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I understand that applications under the same domain name can talk to each other
I understand that we can set the various style attributes from code behind using
I understand that callable's call can throw the exception to the parent method calling
I understand that: '\n' // literally the backslash character followed by the character for
I understand that JVM and CLR were designed as stack-based virtual machines. When JIT
I understand that the em measurement is a relative unit for font-size, relative to
I understand that this question may be subjective, this is why I need an
I understand that storage history is something that is better to keep for vcs
I understand that in CUDA's memory hierachy, we have things like shared memory, texture
I understand that the functional style prefers var or val List of a mutable,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.