I am trying to fix an issue that it is not clear to me.
When calling to Environment.Exit(0)
, it takes about 22 sec to close the application.
if (AppDomain.CurrentDomain.IsDefaultAppDomain())
{
Environment.Exit(exitCode);
}
Have you got any idea what is happening behind the scene? I though maybe an exception is thrown but I checked all the checkboxes in Exceptions dialog.
What's happening behind the scenes is quite clear if you understand how .NET applications work, and how Environment.Exit
works.
In short, Environment.Exit
is not the fastest way to exit an arbitrary application. It still waits for any pending finalizers to run (if they run fast enough, they only have 30 seconds total IIRC). If you're using e.g. sockets, it's perfectly possible that the finalizers take a few seconds to run.
The easiest way to check is of course to use the debugger - just Pause when doing the shutdown, and you'll see which threads are actually executing, and what it is they are executing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With