예제 #1
0
        public static async Task ExecuteThreadAsync(string infotext, Func <Task> taskMethod, Action <Exception> finishAction)
        {
            if (WaitDialogStarted != null)
            {
                WaitDialogStarted(null, null);
            }
            _ThreadDialog = new WaitDialog();
            _ThreadDialog.Show(infotext + " ...");
            try
            {
                await taskMethod();
            }
            catch (Exception ex)
            {
                _Exception = ex;
            }

            if (_ThreadDialog != null)
            {
                _ThreadDialog.Close();
            }
            if (WaitDialogEnded != null)
            {
                WaitDialogEnded(null, null);
            }
            _ThreadDialog = null;

            finishAction(_Exception);
            _Exception = null;
        }
예제 #2
0
 /// <summary>
 /// Starts the finish action that will be done on the GUI-Thread and removes the progressring from the GUI
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 static void _Worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     _Exception = e.Error;
     if (_Worker != null)
     {
         _Worker.DoWork             -= _Worker_DoWork;
         _Worker.RunWorkerCompleted -= _Worker_RunWorkerCompleted;
     }
     if (_ThreadDialog != null)
     {
         _ThreadDialog.Close();
     }
     _Action       = null;
     _ThreadDialog = null;
     if (_Worker != null)
     {
         _Worker.Dispose();
     }
     _Worker = null;
     if (_FinishedAction != null)
     {
         _FinishedAction(_Exception);
     }
 }