I’ve been using Google Chrome for a while now and I noticed that it features very elegant crash control.
Just before crashing, google chrome gave a message saying “Woah! Google Chrome has crashed. Restart now?“. And right after, I’d get a standard Windows XP “This program has encountered a problem and needs to close.” with the “Debug”, “Don’t send” and “Send Error Report” buttons.
My question is how can you program your compiled application to detect a crash condition in advance? If you have knowledge of how to do it in any programming language / platform would be great.
Thanks
Google Chrome uses a technique (often called process separation) where the ‘host’ UI manages child processes that it can detect becoming unresponsive (or worse, throwing an error and closing). It starts a new process for each tab you open.
Here’s an article describing this in a bit more detail.
Using .net’s Process class, you can start processes, check if they’re responsive and even kill them.
If you want to embed a process’ window within your own, you can use platform functions such as SetParent to move one window within another. I’m afraid I’m not aware of a managed alternative to SetParent when working with Forms, but I suspect one exists so it’s worth searching for that before using SetParent.
If the host process crashes, simply using something like
AppDomain.CurrentDomain.UnhandledExceptionwill allow you to receive a notification that a top-level exception has occurred, but by this stage you’re unlikely to be able to predict the state of objects within your app and restarting (along with some logging and a notification to the user) is probably your only sensible option.Handling top-level exceptions is covered in detail here.