public void Worker_RunWorkCompleted(object sender, RunWorkerCompletedEventArgs e) { try { if (Mode == ShowMode.Progress) { CloseProgressForm(); } if (WorkerThread != null && WorkerThread.ThreadState == ThreadState.Aborted) { WorkStoped?.Invoke(new DoWorkEventArgs <T>(WorkArg)); } else { RunWorkCompleted?.Invoke(new RunWorkerCompletedEventArgs <T>(e.Result, e.Error, e.Cancelled)); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { StopWorker(); StopTimer(); } }
/// <summary> /// Completed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Worker_RunWorkCompleted(object sender, RunWorkerCompletedEventArgs e) { try { if (_mfrmProgressForm != null) { _mfrmProgressForm.Close(); _mfrmProgressForm.Dispose(); _mfrmProgressForm = null; } if (_mWorker != null) { _mWorker.DoWork -= Worker_DoWork; _mWorker.RunWorkerCompleted -= Worker_RunWorkCompleted; try { if (_mWorkerThread != null && _mWorkerThread.IsAlive) { _mWorkerThread.Abort(); } } catch (Exception) { } } //In timer, When stop progress will make thread throw AbortException if (_mWorkerThread != null && _mWorkerThread.ThreadState == ThreadState.Aborted) { WorkStoped?.Invoke(new DoWorkEventArgs <T>(_mWorkArg)); } else { RunWorkCompleted?.Invoke(new RunWorkerCompletedEventArgs <T>(e.Result, e.Error, e.Cancelled)); } } catch (Exception ex) { throw ex; } }
private void Bgw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { RunWorkCompleted?.Invoke(this, e); }