Reputation: 1390
assume I have a thread which is still running when the application is terminating
(This thread can not terminate because it waits for a Windows api call to return and that can be long...)
What happens to the thread if the application is closed ?
Can it raise an exception (I'm under Delphi) ?
Upvotes: 2
Views: 1978
Reputation: 612854
I'd say that an exception is very plausible. When you call Application.Terminate
this will lead to the following sequence of events:
PostQuitMessage
.Application.Terminated
being set to True
.Application.Run
returning.System.Halt
is called.DoneApplication
which will tear down Application
and all components that it owns. Hmm, better hope your thread does not access anything owned by Application
.FinalizeUnits
is called. Uh-oh. Memory manager is shut down, and lots more beside.ExitProcess
is called. Now your thread is killed.Your thread will carry on running until the call to ExitProcess
. If it executes any code at all that would be affected by the calls to DoneApplication
and FinalizeUnits
, then you should expect problems.
Upvotes: 7