[英]How to pass unhandled exception to application catch block in thread
I currently have an application that opens an ActiveX object that displays information to the user. 我目前有一个打开可向用户显示信息的ActiveX对象的应用程序。 The COM object needs to be in a new thread in order to be modal.
COM对象需要处于新线程中才能成为模式对象。 There are currently a couple of issues I am having with it:
目前,我遇到了几个问题:
A couple of solutions could be: 一些解决方案可能是:
Code for the Show method is as follows: Show方法的代码如下:
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. 我不确定如何在主线程中访问此方法,并且已经尝试使用BeginInvoke,但是base.Show()必须在运行DocViewer.InitComm之前打开窗口。
Thanks in advance for any help! 在此先感谢您的帮助!
To fix this issue, I was able to change the: 为了解决这个问题,我可以更改:
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
to 至
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException);
this solved the issue. 这解决了问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.