private void _worker_ProgressChanged(object sender, ProgressEventArgs e) { if (_closed) { return; } if (InvokeRequired) { Invoke(new EventHandler <ProgressEventArgs>(_worker_ProgressChanged), sender, e); } else { if (this.IsDisposed) { return; } if (e.Error != null) { if (!(e.Error is UserCancellationException)) { MessageBox.Show(this, e.Error.Message, "Operation Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } _worker.ProgressChanged -= new EventHandler <ProgressEventArgs>(_worker_ProgressChanged); _error = e.Error; _result = null; _closed = true; _log.Debug("Closing the progress dialog..."); this.Close(); _log.Debug("Closed the progress dialog."); } else { lblPrimaryMsg.Text = e.Message; pbrPrimaryProgress.Value = e.Progress; if (e.NestedProgress != null) { lblSecondaryMsg.Text = e.NestedProgress.Message; pbrSecondaryProgress.Value = e.NestedProgress.Progress; } else { if (pbrSecondaryProgress.Value != 0) { pbrSecondaryProgress.Value = 0; lblSecondaryMsg.Text = string.Empty; } } // else if (e.IsDone) { _worker.ProgressChanged -= new EventHandler <ProgressEventArgs>(_worker_ProgressChanged); _result = _worker.Result; _closed = true; _log.Debug("Closing the progress dialog..."); this.Close(); _log.Debug("Closed the progress dialog."); } } // else } // else }