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 6164657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:01:52+00:00 2026-05-23T22:01:52+00:00

Environment: Let’s say I have a main application that: Listen for requests for tasks

  • 0

Environment:

Let’s say I have a main application that:

  • Listen for requests for tasks to do,
  • Perform those tasks (that use some resources (in a physical meaning)) one after another,
  • Must be able to instantly stop a pending task to dispose the resources.

I got two timers:

  • On the timer1 tick, the application is retrieving new requests and store them in a Queue,
  • On the timer2 tick, the application is dequeueing a request to perform the task in a new Thread.

When a user ask to stop all tasks to have the resources free, I plan to simply kill the thread running the current task with Thread.Abort().

Problem:

I would like to be able to save some last configuration when killing the thread from the thread class.

Question:

Is there a way to detect when the thread is killed, like a Thread.OnAborting() event?

Or maybe could I catch the ThreadAbortException raised when calling the Thread.Abort() method? (if so, I don’t really know how to do it, could you provide some code example?)

  • 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-23T22:01:53+00:00Added an answer on May 23, 2026 at 10:01 pm

    Other than catching the ThreadAbortException no other mechanism exists. Of course, you really do not want to be calling Thread.Abort anyway because the ThreadAbortException gets injected asynchronously and those injections points can be unpredictable. For example, it could be in the middle of a write which might leave the entire AppDomain in a corrupted state. .NET 2.0 added constrained execution regions which makes dealing with thread aborts a lot safer and easier to handle, but it is still incredibly difficult to author a block of code that can guarantee that the AppDomain will not get corrupted. My advice is to punt on the Thread.Abort idea.

    Instead what you want to do is send a signal to the thread and allow it terminate gracefully on its own. This can be done with the following mechanisms.

    • Poll a flag
    • Use wait handles
    • Call Thread.Interrupt
    • Use the cancellation mechanisms built into the APIs of long running operations

    You can see my answer here for more information.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say in a Rails app you have some gems that you use in
We have an application running on a loadbalanced environment, let say webserver A and
Let's say I have a struct that contains local environments: public struct Environments {
Let's say I have a handle to device context (naturally, in Windows environment): HDC
First let me say that I know it's better to use the subprocess module,
Ok, so let's say that I want to try virtualization in my environment. I
Let's say I have a rails app with content that's read-only to the public,
Let's just say I have an XML file that looks like this: <?xml version=1.0
Let's say I have a list of objects in the global environment. How would
Let's say in an environment I don't have easy access to trig functions, or

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.