I currently have an application that opens an ActiveX object that displays information to the user. The COM object needs to be in a new thread in order to be modal. There are currently a couple of issues I am having with it:
- I use a base.Show() method that is used to display the ActiveX object, and it throws an InvalidOperationException during runtime which is shown through VisualStudio by throwing Common Language Runtime Exceptions.
- In an attempt to handle this exception, it is encapsulated in a try/catch block, but is never caught by the catch. Because it is unhandled, I attempted to use Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException) which was suggested in multiple posts on SO.
- Once the base.Show() is hit, a dialog appears and if continued through it, the program runs without issue.
A couple of solutions could be:
- Disable the dialog box that shows that the exception is unhandled.
- When the exception is thrown, log it, but still allow the base.Show() to execute.
- Open up a window without base.Show() that will allow the ActiveX control to show.
Code for the Show method is as follows:
public void Show(string url, int entityId, string sessionId, int projId, string docId)
{
try
{
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
base.Show(); //exception occurs here
}
catch (Exception ex)
{
//continue without dialog because once continuing in the dialog, application runs without error
Logger.Error("Base.Show() throws InvalidOperationException, but continuing will bypass issue", ex);
}
try
{
this.DocViewer.InitComm(url, entityId, sessionId, projId, docId);
}
catch (Exception ex)
{
Logger.Error("Error opening papervision viewer", ex);
throw;
}
}
I am unsure how to access this method in the main thread, and have attempted to use BeginInvoke, but the base.Show() must open the window before the DocViewer.InitComm is run.
Thanks in advance for any help!
To fix this issue, I was able to change the:
to
this solved the issue.