Which segment should you use?

You are customizing a Windows Form to asynchronously update a database in a method named WorkHandler. You need to ensure that the form displays a message box to the user that indicates the success of failure of the update. Which segment should you use?

You are customizing a Windows Form to asynchronously update a database in a method named WorkHandler. You need to ensure that the form displays a message box to the user that indicates the success of failure of the update. Which segment should you use?

A.
private void StartBackgroundProcess() {
bgwExecute.DoWork += new Do WorkEventHandler(WorkHandler);
bgwExecute.RunWorkerCompleted +=
new RunWorkerCompletedEventHandler(CompletedHandler);
bgwExecute.RunWorkerAsync();
}
void CompletedHandler(object sender, RunWorkerCompletedEventArgs e) { bool result = (bool) e.Result;
MessageBox.Show("Update " + (result ? "was successfull" : "failed"));) }
void WorkHandler(object sender, DoWorkEventArgs e) { // …
Result = true;
}

B.
private void StartBackgroundProcess() {
bgwExecute.ProgressChanged +=
new ProgressChangedEventHandler(CompletedHandler);
ThreadStart tsBackground = new ThreadStart(WorkHandler);
bgwExecute.RunEorkAsync(tsBackground);
}
void ProgressHandler(object sender, ProgressChangedEventArgs e) { bool result = (bool)e.UserState;
MessageBox.Show("Update " + (result ? "was successful" : "failed")); }
void WorkHandler() {
// …
bgwExecute.ReportProgress(100, true);
}

C.
private void StartBackgroundProcess() {
bgwExecute.RunWorkerCompleted +=
new RunWorkerCompletedEventHandler(CompletedHandler);
ThreadStart tsBackground = new ThreadStart(WorkHandler);
bgwExecute.RunEorkAsync(tsBackground);
}
void CompletedHandlar(object sender, RunWorkerCompletedEventArgs e) { bool result = (bool)e.Result;
MessageBox.Show("Update " + (result ? "was successful" : "failed")); }
void WorkHandler() {
// …
Result = true;
}

D.
Private void StartBackgroundProcess() {
bgwExecute.DoWork += new Do WorkEventHandler(WorkHandler);
bgwExecute.RunWorkerCompleted +=
new RunWorkerCompletedEventHandler(CompletedHandler);
bgwExecute.RunWorkerAsync();



Leave a Reply 0

Your email address will not be published. Required fields are marked *