c# – BackgroundWorker RunWorkerCompletedEventArgs.Cancelled始终为false

前端之家收集整理的这篇文章主要介绍了c# – BackgroundWorker RunWorkerCompletedEventArgs.Cancelled始终为false前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
简单来说:

我通过调用BackgroundWorker上的CancelAsync()方法取消我的操作,并且当执行落在事件RunWorkerCompleted中时,RunWorkerCompletedEventArgs上的“取消”属性为false.我无法弄清楚我应该将其设置为true,因为这是一个EventArgs属性.

任何人都可以给我一些帮助吗?
另外,对不起,如果它是一个重复的,但我找不到任何有关的问题.

解决方法

MSDN

The Cancelled property of
RunWorkerCompletedEventArgs
indicates whether a cancellation
request was processed by the
background operation.

If your code in the DoWork event handler detects a cancellation request by checking the CancellationPending flag and setting the Cancel flag of DoWorkEventArgs to true,the Cancelled flag of RunWorkerCompletedEventArgs also will be set to true.

原文链接:https://www.f2er.com/csharp/92691.html

猜你在找的C#相关文章