Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在主应用程序线程中捕获 BackgroundWorker 中发生的异常的最佳方法是什么。我在 BackgroundWorker 中处理了密集的 UPD 操作,但是当发生异常时,我的主应用程序无法记录发生的事情。请推荐最佳实践。
谢谢
您应该处理该RunWorkerCompleted事件,该事件将在您的主应用程序线程上触发。
RunWorkerCompleted
RunWorkerCompletedEventArgs.Error将包含异常,如果没有异常,则为 null。
RunWorkerCompletedEventArgs.Error