| 发表于:2007-02-14 13:51:445楼 得分:0 |
/// <summary> /// handle the loadcompleted event. this event is raised when the backgroundworker dowork event /// handler has finished EXECuting /// the runworkercompletedeventargs contains information about the task /// - the result, whether it was canceled, if there was an error and so on /// </summary> private void backgroundworker1_runworkercompleted(object sender, system.componentmodel.runworkercompletedeventargs e) { btncancel.enabled = false; btnstart.enabled = true; operationtoolstripprogressbar.value = 0; operationtoolstripprogressbar.visible = false; operationtoolstriptextprogresspanel.text = "ready "; if (e.cancelled == true) { messagebox.show( "background task canceled ", "async backgroundworker sample "); } else { // //note: if the web service returned an error e.result will throw the exception associated with the error // // you can also check for e.error: // // if (e.error != null) { // } // try { txtoutput.text = e.result.tostring(); messagebox.show( "background task completed ", "async backgroundworker sample "); } catch (exception ex) { messagebox.show(ex.message, "async backgroundworker sample ", messageboxbuttons.ok, messageboxicon.exclamation); } } } /// <summary> /// handle the progresschanged event. this event is raised during the EXECution of /// dowork is reportprogress is called. it can be used to give progress feedback to the /// user. /// /// the progresschangedeventargs contains the percentage complete as reported by reportprogress. /// /// note: this is only supported if you set workerreportsprogress = true /// /// </summary> private void backgroundworker1_progresschanged(object sender, system.componentmodel.progresschangedeventargs e) { operationtoolstripprogressbar.value = e.progresspercentage; } } } | | |
|