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 aQueue
, - On the
timer2
tick, the application is dequeueing a request to perform the task in a newThread
.
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?)