You are customizing a Windows Form to use a BackgroundWorker component named bgwExecute. bgwExecute performs a database operation in an event handler named WorkHandler. You need to ensure that users can see the progress of the database operation by viewing a progress bar named pbProgress. You want the progress bar to appear when the database operation is 50 percent complete.
Which code segment should you use?
A.
public void StartBackground() {
bgwExecute.WorkerReportsProgress = true;
bgwExecute.ProgressChanged += new ProgressChangedEventHandler(ProgressHandler);
bgwExecute.RunWorkerAsync();
}
void WorkHandler(object sender, DoWorkEventArgs e) {
bgwExecute.ReportProgress(50);
}
void ProgressHandler(object sender, ProgressChangedEventArgs e) {
pbProgress.Value = e.ProgressPercentage;
}
B.
public void StartBackground() {
bgwExecute.WorkerReportsProgress = true;
bgwExecute.ProgressChanged += new ProgressChangedEventHandler(ProgressHandler);
ThreadStart t = new ThreadStart(WorkHandler);
bgwExecute.RunWorkerAsync(t);
}
void WorkHandler() {
bgwExecute.ReportProgress(50);
}
void ProgressHandler(object sender, ProgressChangedEventArgs e) {
pbProgress.Value = e.ProgressPercentage;
}
C.
public void StartBackground() {
bgwExecute.WorkerReportsProgress = true;
bgwExecute.ProgressChanged += new ProgressChangedEventHandler(ProgressHandler);
Thread t = new Thread(new ThreadStart(WorkHandler));
bgwExecute.RunWorkerAsync(t);
}
void WorkHandler() {
bgwExecute.ReportProgress(50);
}
void ProgressHandler(object sender, ProgressChangedEventArgs e) {
pbProgress.Value = e.ProgressPercentage;
}
D.
public void StartBackground() {
bgwExecute.WorkerReportsProgress = true;
bgwExecute.DoWork += new DoWorkEventHandler(WorkHandler);
bgwExecute.ProgressChanged += new ProgressChangedEventHandler(ProgressHandler);
bgwExecute.RunWorkerAsync();
}
void WorkHandler(object sender, DoWorkEventArgs e) {
bgwExecute.ReportProgress(50);
}
void ProgressHandler(object sender, ProgressChangedEventArgs e) {
pbProgress.Value = e.ProgressPercentage;
}