简体   繁体   English

从UI线程中抛出异常

[英]Throw An exception from the UI thread

The main UI thread is showing a popup dialog (Form). 主UI线程显示弹出对话框(Form)。 I would like to force the UI thread to close this popup dialog and throw an exception to the UI thread (from another thread) when an abort request is received. 我想强制UI线程关闭此弹出对话框,并在收到中止请求时向UI线程(从另一个线程)抛出异常。

Is that possible? 那可能吗?

Don't throw an exception. 不要抛出异常。 An exception can't be caught be a different thread. 异常不能被捕获为不同的线程。 Expose a public method that will call close on your form: 公开一个将在您的表单上调用close的公共方法:

DlgForm.BeginInvoke(new MethodInvoker(Close));

and set an 'aborted' state flag that the UI can use after the dialog closes. 并设置一个'aborted'状态标志,UI可以在对话框关闭后使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM