Here's my simple C# console app:
using System.Diagnostics;
using System.Threading;
public static class Program
{
public static int Main(string[] args)
{
var e = new AutoResetEvent(false);
ThreadPool.QueueUserWorkItem(state =>
{
Process.Start("nonexistent path");
e.Set();
});
e.WaitOne();
return 0;
}
}
If I run this program within a debugger, it will hang on shutdown. If I replace the line Process.Start("nonexistent path");
(which throws System.ComponentModel.Win32Exception
with throw new System.Exception();
, it doesn't hang and the program terminates as expected.
It seems to me that .NET/CLR or the debugger must handle Win32Exception
in some special way. Is this expected behaviour?
This is running on .NET/CLR 4.0 where unhandled exceptions on worker threads should terminate the application: this is the case for CLR 2.0 and later (http://msdn.microsoft.com/en-us/library/ms228965.aspx).
UPDATE
So far, I've only been able to reproduce this problem on 32-bit Windows OS's when launching the program from a Cygwin terminal.