I have a worker thread that is vital for my application.
It is created with new Thread( method ).Start();
I don't join it, I just expect that is runs as long as my program runs.
However, it can happen that there is an exception caught on this thread; and as a consequece the thread will (beside some last logging) shutdown. A recovery is not possible for this critical error. Since the thread is vital for the app, it has to shutdown, too.
Now my question is: How can I monitor the state of my thread?
Would you
- Poll the
IsAlive
property? - rethrow the caught exception and work with
AppDomain.CurrentDomain.UnhandledException
? - implement an
event
that will signal the end of my background thread? - use a
BackgroundWorker
, which implementsRunWorkerCompleted
? (But is a BackgroundWorker really the right choice for long running threads?) - something completley different?
EDIT:
Right now, I solved the problem by calling Application.Exit()
-> crash early and often. That's an option, too :)