1
我有一些backgroundWorker類的問題。我希望我可以在一個函數中取消Backroundworker,並且在它從頭開始Backgroundworker後,它引起了比賽,我不知道如何改變它。是否有任何替代的BackgroundWorker在.net 3.5C#Backgroundworker比賽 - 任何替代?
編輯:
My code:
BackgroundWorker worker = new BackgroundWorker();
public void Func()
{
if(worker.IsBusy)
{
worker.CancelAsync();
worker = new BackgroundWorker();
}
View.Clear();
worker.WorkerSupportsCancellation = true;
worker.DoWork += delegate(object s, DoWorkEventArgs args)
{
BackgroundWorker sender = s as BackgroundWorker;
if(sender.CancellationPending)
{
args.Cancel = true;
return;
}
View.Generate(Filter);
};
worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
{
if(args.Error != null)
{
MessageBox.Show(args.Error.Message);
return;
}
BackgroundWorker sender = s as BackgroundWorker;
if(args.Cancelled)
{
View.Clear();
}
};
worker.RunWorkerAsync();
}
的問題是:cancelAsync犯規密切工人在所有和我的看法是不正確的方式產生
可能尋找到這個值得http://stackoverflow.com/questions/69665 73/how-is-backgroundworker-cancellationpending-thread-safe/6966759#6966759 – CharithJ 2011-08-17 12:21:20