/// <summary> /// Return true if operation completed successfully, otherwise false if cancelled or failed. /// Used for blocking operations that still want a feedback to the user /// or a way to cancel the operation. Runs the given action on a new thread /// to prevent UI from freezing. /// </summary> /// <param name="work"></param> /// <param name="SupportsCancel"></param> public static bool Show(string Title, string Text, ThreadStart work, bool SupportsCancel = false, string ThreadName = "Progress Bar") { PopupProgressBar bar = new PopupProgressBar(Title, Text, new Action <DoWorkEventArgs, BackgroundWorker>( (DoWorkEventArgs args, BackgroundWorker worker) => { Thread thread = new Thread(work); thread.Name = "Worker Thread - " + ThreadName; thread.IsBackground = true; thread.Start(); while (thread.IsAlive) { if (worker.CancellationPending) { thread.Abort(); thread.Join(); args.Cancel = true; break; } } }), true, SupportsCancel); bar.ShowDialog(); bar.Close(); return(bar.cancelled); }
/// <summary> /// Return true if operation completed successfully, otherwise false if cancelled or failed. /// Use ProgressBarStyle as the UserState to change that. /// </summary> /// <param name="work"></param> /// <param name="SupportsCancel"></param> public static bool Show(string Title, string Text, Action <DoWorkEventArgs, BackgroundWorker> work, bool InfiniteProgress = false, bool SupportsCancel = false) { PopupProgressBar bar = new PopupProgressBar(Title, Text, work, InfiniteProgress, SupportsCancel); bar.ShowDialog(); bar.Close(); return(bar.cancelled); }