I attach a debugger by passing '-d' as a command line parameter to my console app. That causes the following code to be called;
bool attachedDebugger = false;
try
{
attachedDebugger = System.Diagnostics.Debugger.Launch();
}
catch (Exception) { }
finally
{
Console.WriteLine(attachedDebugger ? "Debugger Attached" : "Failed to attach debugger");
}
After the Visual Studio 2010 JIT window pops up I sometimes change my mind and don't want to debug, so I dismiss the dialog. If I don't attach one then the Application exits immediately without anything being written to the console.
I know that this it a bit of an edge use case, I should just remove the '-d' from the command line if I don't want to debug. The reason for my question is that I wish to understand what's happening.
I thought the finally block is always called, furthermore I would expect my application to continue if we fail to attach a debugger.
Debugger.Launch()
call
System.Exit
on failure to attach?EDIT Thanks @Moo-Juice I now know that a return value of false
implies a debugger was already attached but the questions above remain unresolved.
This is a reported bug in dotnet 4.0
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