ActiveX in WebBrowser in WinForms crashing whole app-Collection of common programming errors

I have a C# WinForms application, that has a WebBrowser control, which loads an html page in which is embedded a 3rd-party ActiveX object, which plays IPTV video. The Active X supplied by Exterity. I have also tried the VLC ActiveX control, which was even more unreliable, with the same symptoms. Same behavior on both XP and Win7.

Intermittently the whole WinForms app exits. I already handle the ThreadException and UnhandledExcetion events thus:

[STAThread]
static void Main(string[] args)
{
    //set up global exception handling
    Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
    Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
    AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

These events do not fire before the app exits; and believe me they do work, because they’ve been in place for a few years now, and have fired many times catching other errors (e.g. timeout database connection) (at which point i restart the whole app)! I see no entries in Windows Event View. My exe process just disappears.

I’ve been reading up on AppDomains, and wondering whether i can put the WebBrowser control in a separate one to the main program/Form; any advice appreciated.

Or are there other ways i can handle, what i presume is, an exception that is going unhandled all the way to the top, at which point the process exits.

  1. Trying to catch and ignore Access Violations is a recipe for introducing memory corruption that can corrupt your application’s data or settings. You’d be better off figuring out why the ActiveX control is crashing (e.g. use WinDBG) and addressing that.