When firing up my Excel add-in, I preserve a handle to an Excel window using the following code:
ExcelWindow = new NativeWindow();
ExcelWindow.AssignHandle(new IntPtr(Application.Hwnd));
When it comes to releasing a handle, I try to do it while shutting down:
private void ThisAddInShutdown(object sender, EventArgs e)
{
try
{
ExcelWindow.ReleaseHandle();
}
catch
{
}
}
When exiting excel in Debug mode, everything works fine. Unfortunately, when running this code on a production system, I get a crash, with no ability to debug what's going on. I get a 'windows is checking this problem' window, subsequently it disappears, and that's it.
It's really not a big deal, but I don't want to annoy the users with something like this. So, does anyone have any idea what it could be and how I could debug this? Thanks.