/// <summary> /// Creates and displays the loading progress bar, while running the workMethod asynchronously. /// Creates Progress objects and passes them into the work method. /// Only returns when the work task is finished, and does not lock down UI thread. /// </summary> public static void VoidBuilder( Action <LoadingUpdater> workMethod) { LoadingDialog dialog = new LoadingDialog(); //Execute the work asynchronously Task.Run(() => { workMethod(dialog.updater); //Dispatch call to appropriate UI Thread to close the modal dialog and resume execution dialog.updater.CloseDialog(); }); //Display window as a Modal Dialog //Execution pauses on this call until the dialog is closed dialog.ShowDialog(); }
/// <summary> /// Creates and displays the loading progress bar, while running the workMethod asynchronously. /// Creates Progress objects and passes them into the work method. /// Returns the result only when the work task is finished, and does not lock down UI thread. /// </summary> public static async Task <T> ReturnBuilder <T>( Func <LoadingUpdater, T> workMethod) { LoadingDialog dialog = new LoadingDialog(); //Execute the work asynchronously Task <T> work = Task.Run(() => { T result = workMethod(dialog.updater); //Dispatch call to appropriate UI Thread to close the modal dialog and resume execution dialog.updater.CloseDialog(); return(result); }); //Display window as a Modal Dialog //Execution pauses on this call until the dialog is closed dialog.ShowDialog(); //Return the result of the work (which will already be finished) return(await work); }