среда, 19 августа 2009 г.

How to know if .Net application is running under debugger

In my application I've got the bug reporting. When an unhandled error occurs - it show the form to let user send the report.

That's good for user, not for developper, because he needs to handle unhandled exceptions with debugger, cuz it's much more informative.

So, we need to lock bug reporting when application is under debugger.

Here's the solution:


if (!Debugger.IsAttached)
{
AppDomain.CurrentDomain.UnhandledException +=
new UnhandledExceptionEventHandler
(CurrentDomain_UnhandledException);
Application.ThreadException +=
new System.Threading.ThreadExceptionEventHandler
(Application_ThreadException);
}



P.S. To use the Debugger class you need using System.Diagnostics namespace

Комментариев нет:

Отправить комментарий