So, I call the thread from managed code as follows:
Action<EFScmTechnologiesContext, long, long> updateReference = UpdateReferenceBaseline;
IAsyncResult ar = updateReference.BeginInvoke(_context, baseline.Id, updatedBaseline.Id, null, null);
I made sure this class destructor was waiting for the thread to finish. Therefore, for most normal cases, a thread is allowed to do its work before the process exists. However, I suspect that there may be conditions (unhandled exceptions from another thread, maybe?), Where the destructor is not called, and the thread terminates without the possibility of terminating it.
What should I do., Either in the delegate or in the wrapper class, to make sure that this thread is allowed to complete regardless of exceptions, interrupts, or exits in another thread?
I read about UnhandledExceptionHandler (), but was not sure what to do with it., I think that by the time the handler is called my thread, it is already a toast. I could also add a try / catch block to the delegate, but that would mean that the thread was already interrupted from running current operations.
I also admit that depending on the exception used, the entire application environment may be toast., So even if I can catch / prevent the thread from interrupting., I probably should only allow it 30 seconds to try to complete my work, and then let her die independently.,.
I see a lot of information about threads and exceptions in general, etc., but very little on the exit process and the last moments of the life cycle., If anyone has a pointer to a good description, please.,