You are customizing a Windows Form to update a database asynchronously by using an instance of a BackgroundWorker component named bgwExecute. You start the component by using the following code.
private void StartBackgroundProcess() {
bgwExecute.DoWork += new DoWorkEventHandler(WorkHandler);
bgwExecute.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CompletedHandler);
bgwExecute.ProgressChanged += new
ProgressChangedEventHandler(ProgressChanged);
bgwExecute.RunWorkerAsync();
}
If the UpdateDB method that is called by the BackgroundWorker component returns the value False, you need to display a message box to the user that indicates that the update failed.
Which code segment should you use?
A.
void WorkHandler(object sender, DoWorkEventArgs e) {
if (!UpdateDB()) MessageBox.Show(“Update failed”);
}
B.
void CompletedHandler(object sender, RunWorkerCompletedEventArgs e) {
if (! UpdateDB()) MessageBox.Show(“Update failed”);
}
C.
void WorkHandler(object sender, DoWorkEventArgs e) {
e.Result = UpdateDB();
}
void CompletedHandler(object sender, RunWorkerCompletedEventArgs e) {
if (!(bool) e.Result) MessageBox.Show(“Update failed”);
}
D.
void WorkHandler(object sender, DoWorkEventArgs e) {
e.Result = UpdateDB();
}
void CompletedHandler(object sender, RunWorkerCompletedEventArgs e) {
if (!(bool) e.Result) bgwExecute.ReportProgress(0);
}
void ProgressChanged(object sender, ProgressChangedEventArgs e) {
if (e.ProgressPercentage==0) MessageBox.Show(“Update failed”);
}