Example #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;
        }
Example #2
0
        private static async Task _ExecuteThreadAsyncNoDialog(Func <Task> taskMethod, Action <Exception> finishAction)
        {
            if (WaitDialogStarted != null)
            {
                WaitDialogStarted(null, null);
            }
            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;
        }
Example #3
0
 /// <summary>
 /// Shows a progressring while the application is doing something in the background
 /// </summary>
 /// <param name="infotext">Text that is shown while the progressring is visible</param>
 /// <param name="threadMethod">Action that can be done on an other thread (f.e. math-stuff)</param>
 /// <param name="finishedMethod">Action that has to be done on the GUI-Thread (GUI-stuff)</param>
 public static void ExecuteThread(string infotext, Action threadMethod, Action <Exception> finishedMethod)
 {
     _ThreadDialog = new WaitDialog();
     _ThreadDialog.Show(infotext + " ...");
     _Action                     = threadMethod;
     _FinishedAction             = finishedMethod;
     _Worker                     = new BackgroundWorker();
     _Worker.DoWork             += _Worker_DoWork;
     _Worker.RunWorkerCompleted += _Worker_RunWorkerCompleted;
     _Exception                  = null;
     _Worker.RunWorkerAsync();
 }
Example #4
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);
     }
 }