private void backgroundWorkerGetDescription_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { try { if (e.Error != null) { string errorMessage = e.Error.Message + (e.Error.InnerException == null ? string.Empty : e.Error.InnerException.InnerException.Message); MessageBox.Show(errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { if (e.Result != null && e.Result is BwArguments) { BwArguments arg = (e.Result as BwArguments); textBoxDescription.Text = arg.Message; } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { this.SetControlVisibility(false); } }
private void backgroundWorkerGetDescription_DoWork(object sender, DoWorkEventArgs e) { try { // Do not access the form's BackgroundWorker reference directly. // Instead, use the reference provided by the sender parameter. BackgroundWorker worker = sender as BackgroundWorker; if (worker.CancellationPending == false) { BwArguments arg = e.Argument as BwArguments; if (arg.Type == JobType.JIRA) { arg.Message = this.GetJiraDescription(arg.ID); } else if (arg.Type == JobType.LCS) { arg.Message = this.GetLcsDescription(arg.ID); } e.Result = arg; } // If the operation was canceled by the user, // set the DoWorkEventArgs.Cancel property to true. if (worker.CancellationPending) { e.Cancel = true; } } catch (Exception) { //throw the exception so that RunWorkerCompleted can catch it. throw; } }