public static void AssignTask(IProgressDialogController progress, ITask task) { var taskManager = new TaskManager(task.Name); taskManager.Enqueue(task); var progressChangedHandler = new EventHandler((o, e) => { progress.SetProgress(taskManager.Progress); if (ProgressScope.ProgressEquals(taskManager.Progress, 1.0)) { progress.CloseAsync(); } }); var statusMessageChangedHandler = new EventHandler((o, e) => progress.SetMessage(taskManager.StatusMessage)); var isIndetermineChangedHandler = new EventHandler((o, e) => { if (taskManager.IsIndeterminate) { progress.SetIndeterminate(); } }); taskManager.ProgressChanged += progressChangedHandler; taskManager.StatusMessageChanged += statusMessageChangedHandler; taskManager.IsIndetermineChanged += isIndetermineChangedHandler; taskManager.Process().Wait(); taskManager.ProgressChanged -= progressChangedHandler; taskManager.StatusMessageChanged -= statusMessageChangedHandler; taskManager.IsIndetermineChanged -= isIndetermineChangedHandler; }
public ProgressDialog(IntPtr ownerHandle) { _ownerHandle = ownerHandle; InitializeComponent(); this.ProgressDialogController = new ProgressDialogController(this); this.Loaded += ProgressDialog_Loaded; this.Unloaded += ProgressDialog_Unloaded; }
public void Dispose() { if (_isDisposed) { return; } _progressController = null; _task = null; _isDisposed = true; }
private void ShowProgressDialog(string title, bool animateShow, bool animateHide, bool cancellable) { var settings = new DialogSettings { UseAnimationOnShow = animateShow, UseAnimationOnHide = animateHide }; var task = DialogManager.Instance.ShowProgressAsync(title, string.Empty, cancellable, settings); task.Wait(); _progressController = task.Result; }
private static Task <IProgressDialogController> ShowExternalProgressDialogAsync(string title, string message, bool isCancellable) { IProgressDialogController controller = null; STATaskFactory.StartNew(() => { var shellHandle = (IntPtr)Application.Current.Dispatcher.Invoke(new Func <IntPtr>( () => new WindowInteropHelper(Application.Current.MainWindow).Handle)); var dialog = new ProgressDialog(shellHandle); var shellRect = (Rect)Application.Current.Dispatcher.Invoke(new Func <Rect>( () => new Rect(Application.Current.MainWindow.WindowState == WindowState.Maximized ? 0 : Application.Current.MainWindow.Left, Application.Current.MainWindow.WindowState == WindowState.Maximized ? 0 : Application.Current.MainWindow.Top, Application.Current.MainWindow.ActualWidth, Application.Current.MainWindow.ActualHeight))); dialog.Left = shellRect.Left; dialog.Top = shellRect.Top; dialog.Width = shellRect.Width; dialog.Height = shellRect.Height; dialog.Title = title; dialog.Message = message; dialog.IsCancellable = isCancellable; dialog.Closed += (s, e) => Dispatcher.CurrentDispatcher.BeginInvokeShutdown(DispatcherPriority.Background); dialog.AnimateAndShow(); controller = dialog.ProgressDialogController; Dispatcher.Run(); }); return(Task.Factory.StartNew(() => { while (controller == null) { Thread.Sleep(10); } return controller; })); }