private void DoBackGroundWork(object sender, int time, PowerTimer timer) { PowerWorkerThread = Thread.CurrentThread; for (int i = time * 60; i > 0; i--) { Thread.Sleep(1000); (sender as BackgroundWorker).ReportProgress(i, timer); } }
private void DoWork(int time, string Arguments) { if (PowerWorker.IsBusy) { PowerWorker.CancelAsync(); PowerWorkerThread.Abort(); PowerWorker = new BackgroundWorker(); } PowerTimer Timer = new PowerTimer(); ParentGrid.Children.Add(Timer); Grid.SetColumn(Timer, 1); PowerWorker.WorkerReportsProgress = true; PowerWorker.WorkerSupportsCancellation = true; PowerWorker.DoWork += (sender, e) => DoBackGroundWork(PowerWorker, time, Timer); PowerWorker.ProgressChanged += Bw_ProgressChanged; PowerWorker.RunWorkerCompleted += (sender, e) => ProgressCompleted(Arguments); PowerWorker.RunWorkerAsync(); Timer.WorkerThread = PowerWorkerThread; }