Which three code segments should you use?

You are customizing a Windows Form to asynchronously update a database. You need to ensure that the form displays a message box to the user that indicates the success or failure of the update.
Which three code segments should you use? (Each correct answer presents part of the solution. Choose three.)

You are customizing a Windows Form to asynchronously update a database. You need to ensure that the form displays a message box to the user that indicates the success or failure of the update.
Which three code segments should you use? (Each correct answer presents part of the solution. Choose three.)

A.
private void StartBackgroundProcess() {
bgwExecute.DoWork += new DoWorkEventHandler(WorkHandler);
bgwExecute.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CompletedHandler);
bgwExecute.RunWorkerAsync();
}

B.
private void StartBackgroundProcess() {
bgwExecute.ProgressChanged += new ProgressChangedEventHandler(CompletedHandler);
ThreadStart tsBackground = new ThreadStart(WorkHandler);
bgwExecute.RunWorkerAsync(tsBackground);
}

C.
private void StartBackgroundProcess() {
bgwExecute.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CompletedHandler);
ThreadStart tsBackground = new ThreadStart(WorkHandler);
bgwExecute.RunWorkerAsync(tsBackground);
}

D.
void WorkHandler(object sender, DoWorkEventArgs e) {
//…
e.Result = true;
}

E.
void WorkHandler(object sender, DoWorkEventArgs e) {
//…
bgwExecute.ReportProgress(100, true);
}

F.
void CompletedHandler(object sender, RunWorkerCompletedEventArgs e) {
bool result = (bool)e.Result;
MessageBox.Show(“Update ” + (result ? “was successful” : “failed”));
}

G.
void ProgressHandler(object sender, ProgressChangedEventArgs e) {
bool result = (bool)e.UserState;
MessageBox.Show(“Update ” + (result ? “was successful” : “failed”));
}



Leave a Reply 0

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