You are creating a Windows application by using the .NET Framework 3.5.You create an
instance of the BackgroundWorker component named backgroundWorker1 To
asynchronously process time-consuming reports in the application.You write the following
code segment in the application. (Line numbers are included for reference only.)
01 private void backgroundWorker1_RunWorkerCompleted( object sender,
RunWorkerCompletedEventArgs e)
02 {
03?
04 }
You need to write a code segment that reports to the application when the background
process detects any of the following actions:
An exception is thrown.
The process is cancelled.
The process is successfully completed.
Which code segment should you insert at line 03?
A.
if (e.Cancelled == null)
MessageBox.Show(“Report Cancelled”);
else
MessageBox.Show(“Report Completed”);
B.
if (e.Result == “Cancelled” || e.Result == “Error”)
MessageBox.Show(“Report Cancelled”);
else
MessageBox.Show(“Report Completed”);
C.
if (backgroundWorker1.CancellationPending)
MessageBox.Show(“Report Cancelled”);
Else
MessageBox.Show(“Report Completed”);
D.
if (e.Error != null)
MessageBox.Show(e.Error.Message);
else if (e.Cancelled)
MessageBox.Show(“Report Cancelled”);
else
MessageBox.Show(“Report Completed”);
Explanation:
Since different messages must be displayed for exceptions, cancellations and completions, the answer choice MUST BE D.