public static RunWorkerCompletedEventArgs RunLongTask(string title, DoWorkEventHandler callback, bool reportsProgress, object args, EventHandler cancelHandler) { using (BusyForm frmLongTask = new BusyForm(title, callback, reportsProgress, args, cancelHandler)) { frmLongTask.ShowDialog(); if (frmLongTask.error != null) { throw frmLongTask.error; } return(frmLongTask.results); } }
private void button1_Click(object sender, EventArgs e) { try { cleardatabase(); RunWorkerCompletedEventArgs taskResult = BusyForm.RunLongTask("Waiting for fingerprint ...", new DoWorkEventHandler(doEnroll), false, null, new EventHandler(CancelScanningHandler)); EnrollmentResult enrollmentResult = (EnrollmentResult)taskResult.Result; } catch (Exception ex) { MessageBox.Show(ex.Message); } }