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; }
/// <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(); }