In addition to the reporting process, the ReportProgress () method can be used as a general asynchronous event dispatcher (for example, to update text in user interface controls):
for (int i = 0; i < nSteps; ++i) { string s = getnStr(); // Update text backgroundWorker1.ReportProgress(0, "My text.."); // Update progress int progress = (int)(100.0 / nSteps * (i + 1)); backgroundWorker1.ReportProgress(progress); }
ProgressChanged event handler will look something like this:
void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e) { if (e.UserState != null) {
alexm source share