worker = new BackgroundWorker();
worker.DoWork += delegate
{
for (int i = 3; i > 0; i--)
{
this.Dispatcher.Invoke((Action)(() => { button1.Content = Convert.ToString(i); }));
System.Threading.Thread.Sleep(1000);
}
};
worker.RunWorkerCompleted += delegate { Button_Click_1(); };
worker.RunWorkerAsync();
Jak zatrzymać taki worker? Mam coś takiego w innej funkcji
worker.CancelAsync();
jednak dostaję błąd:
A first chance exception of type 'System.InvalidOperationException' occurred in System.dll
Additional information: Proces BackgroundWorker nie obsługuje anulowania. Zmodyfikuj stan procesu WorkerSupportsCancellation, tak aby proces obsługiwał anulowanie.