I have a custom TraceListener
that is supposed to replace the DefaultTraceListener, so that I can do things like customizing the dialog that shows when the user hits a Debug.Assert.
When my app isn't quite working right, I attach the debugger and will try to query properties to see their value. Sometimes these properties trigger a Debug.Assert.
If the assert happens while I've paused the code and I'm looking at it with the debugger, I want to totally ignore the assert and just move on. If the assert happens when the code is running, I want the custom window to pop up.
Is there any way to detect that I'm running code while the application is paused by a debugger?
I've temporarily worked around the issue using
Debugger.IsAttached
. If it's true, then there's a debugger attached, and I disable the custom dialog and just fall back toDefaultTraceListener.Fail
. This isn't ideal, because it means that my custom dialog only shows up when there's no debugger attached. But that means that my users will see it in the situation where I want them to (running debug mode with no debugger), which I guess is good enough.