Esempio n. 1
0
 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();
 }