How to make a C# program crash without "this program has stopped working" dialog?

Red Squirrel

No Lifer
May 24, 2003
70,674
13,836
126
www.anyf.ca
I have a C# app that is a game server, it's a huge app. NORMALLY when it crashes, it simply detects that it crashed, writes an error log, and restarts itself. Basically the main program loop is inside an exception handler so it just catches the exception and writes to log file and relaunches itself and terminates. (ex: it starts a brand new process)

But every now and then, for some reason, it crashes but throws the "this program has stopped working" dialog. This halts the entire program and it cannot do it's proper crash handling. Is there a reason why it randomly does this? The issue is that it causes the app to completely hang and if I'm not there to notice that it's down or I get the alert on my phone and am not near a computer with VPN access to my home network it can cause downtime.

Obviously I should be trying to find what crashes it, and we normally don't deploy anything new to production before it's been fully tested bug free, but every now and then something we overlooked may slip through.
 

Red Squirrel

No Lifer
May 24, 2003
70,674
13,836
126
www.anyf.ca
I doubt it's the latest, the app is very specific to which version it needs. I think it's on 4. something. The main program loop is actually in an try/catch statement, but I'll read up more on the UnhandledExceptionEventHandler and see if that helps. This crash happens maybe like once a month if that so it will be hard to tell for sure, but at least gives me something to try.