private void PerformBG(BaseForm control, Action bgwork, Action fgwork, Action <Exception> customErrorHandler = null) { control.IsBusy = true; new Thread(() => { Exception exception = null; try { bgwork(); } catch (Exception ex) { exception = ex; } control.Invoke((Action)(() => { if (exception != null) { if (customErrorHandler != null) { customErrorHandler(exception); } else { new ReportBugForm(exception).ShowDialog(); } IsBusy = false; return; } try { fgwork(); } catch (Exception ex) { new ReportBugForm(ex).ShowDialog(); } finally { IsBusy = false; } })); }).Start(); }
private void PerformBG(BaseForm control, Action bgwork, Action fgwork, Action<Exception> customErrorHandler = null) { control.IsBusy = true; new Thread(() => { Exception exception = null; try { bgwork(); } catch (Exception ex) { exception = ex; } control.Invoke((Action)(() => { if (exception != null) { if (customErrorHandler != null) customErrorHandler(exception); else MessageBox.Show(control, "An error occurred executing a background task:\r\n\r\n" + exception.ToString()); IsBusy = false; return; } try { fgwork(); } catch (Exception ex) { MessageBox.Show(control, "An error occurred exucuting a foreground task:\r\n\r\n" + ex.ToString()); } finally { IsBusy = false; } })); }).Start(); }
private void PerformBG(BaseForm control, Action bgwork, Action fgwork, Action<Exception> customErrorHandler = null) { control.IsBusy = true; new Thread(() => { Exception exception = null; try { bgwork(); } catch (Exception ex) { exception = ex; } control.Invoke((Action)(() => { if (exception != null) { if (customErrorHandler != null) customErrorHandler(exception); else new ReportBugForm(exception).ShowDialog(); IsBusy = false; return; } try { fgwork(); } catch (Exception ex) { new ReportBugForm(ex).ShowDialog(); } finally { IsBusy = false; } })); }).Start(); }