Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug a disappearing app

On a Windows 2003 server I have a pure .NET 3.5 C# app (no unmanaged code). It connects to various other remote systems via sockets and acts like a data hub. It runs for 10-15 hours fine with no problem but from time to time it just disappears. If I watch the app using task manager the memory usage remains constant.

In the Main() function I wrap the invocation of the rest of the app in a try .. catch block which it just blows completely past - the catch block which logs the exception to a file is ignored. If I manually raise an exception for testing, the catch block is invoked.

Prior to entering the try .. catch I do :

Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException);

The system has Dr. Watson on it, but nothing gets written in the directory DRWTSN32.EXE is pointing to.

How can I catch whatever exception is causing this?

like image 600
rc1 Avatar asked Dec 18 '22 10:12

rc1


2 Answers

Try using the debugging tools from microsoft. You can download them from here.

Use adplus to capture the crash and then windbg to analyze it.

adplus -crash -pn your.exe -quiet

Lots of great info about debugging on windows on this blog.

like image 129
Joel Cunningham Avatar answered Dec 24 '22 01:12

Joel Cunningham


If this is a Windows Forms app, then it's likely that the unhandled exception is being caught by the window message pump, which is why you never see it. To deal with this, see my answer here.

If it's a Windows service, then the exception might be appearing on a background thread and not being marshalled back to your main thread. To deal with this, you need to marshal any background thread back to your main thread, and the exception will be re-thrown there so that you can catch it.

If it's a console app, then I'm a bit mystified.

EDIT: Your comment says this is a Windows Forms app. In that case, you're probably not seeing the exception because it's being handled by the built-in Windows Forms exception handler that does the following by default:

  • Catches an unhandled managed exception when:
    • no debugger attached, and
    • exception occurs during window message processing, and
    • jitDebugging = false in App.Config.
  • Shows dialog to user and prevents app termination.

You can disable this behaviour by setting jitDebugging = true in App.Config. Then you should be able to see the unhandled exception by registering for the event Application.ThreadException, e.g. in C#:

Application.ThreadException += new Threading.ThreadExceptionHandler(CatchExceptions);
like image 20
HTTP 410 Avatar answered Dec 24 '22 01:12

HTTP 410