示例#1
0
 public static void ShowWaitingPopup(string Header,
                                     string bt1Text,
                                     FinishCB finishCB = null,
                                     ProgressCB cb     = null,
                                     PopupButton.ButtonAction cancelCB = null)
 {
     instance.SetupText(Header, "");
     instance.SetupButton(bt1Text, "", "");
     instance.TextProgressCB     = cb;
     instance.Button1.OnReleased = cancelCB;
     instance.progressDoneCB     = finishCB;
     instance.mShowProgress();
 }
示例#2
0
        public ProgressUI(Window?owner, string title, string desc, ImageSource?image, CancellationToken cancel, WorkerFunc worker, object?arg = null, ThreadPriority priority = ThreadPriority.Normal)
            : this(owner, title, desc, image, cancel)
        {
            try
            {
                worker ??= DefaultWorkerFunc;
                void DefaultWorkerFunc(ProgressUI ui, object?a, ProgressCB p)
                {
                    // Default worker function just waits till cancel is signalled
                    for (; !CancelPending; Thread.Sleep(100))
                    {
                        p(new UserState {
                        });
                    }
                }

                // Start the worker task
                m_thread = new Thread(new ThreadStart(ThreadEntry))
                {
                    Name         = "ProgressUI",
                    Priority     = priority,
                    IsBackground = true,
                };
                void ThreadEntry()
                {
                    var progress_cb = new ProgressCB(UpdateProgress);

                    try
                    {
                        // Run the worker task
                        worker(this, arg, us => Dispatcher.BeginInvoke(progress_cb, us));
                        Dispatcher.BeginInvoke(progress_cb, new UserState {
                            FractionComplete = 1f
                        });
                    }
                    catch (Exception ex)
                    {
                        if (ex is OperationCanceledException)
                        {
                            m_cancel.Cancel();
                        }
                        else
                        {
                            Error = ex;
                        }
                    }

                    // Set the event to say "task done"
                    Done.Set();
                    Dispatcher.BeginInvoke(progress_cb, new UserState {
                        CloseDialog = true
                    });
                }
                m_thread.Start();
            }
            catch
            {
                Dispose();
                throw;
            }
        }