简体   繁体   中英

Throw An exception from the UI thread

The main UI thread is showing a popup dialog (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.

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:

DlgForm.BeginInvoke(new MethodInvoker(Close));

and set an 'aborted' state flag that the UI can use after the dialog closes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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