Which code segment should you use?

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 Do WorkEventHandler(WorkHandler); bgwExecute.DoWorkerCompleted +=
new Do WorkerCompletedEventHandler(CompletedHandler); bgwExecute.ProgressChanged += new
ProgressChangedEventHandler(ProgressHandler);
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?

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 Do WorkEventHandler(WorkHandler); bgwExecute.DoWorkerCompleted +=
new Do WorkerCompletedEventHandler(CompletedHandler); bgwExecute.ProgressChanged += new
ProgressChangedEventHandler(ProgressHandler);
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) {
Result = UpdateDB();
}
void CompletedHandler(object sender, RunWorkerCompletedEventArgs e) {
if (!(bool) e.Result MessageBox.Show("Update failed"); }

D.
void WorkHandler(object sender, DoWorkEventArgs e) {
Result = UpdateDB();
}
void CompletedHandler(object sender, RunWorkerCompletedEventArgs e) {



Leave a Reply 0

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