public ProgressWindow(string title, ProgressWork worker, bool cancelSupport = false) { InitializeComponent(); this.title = title; this.Text = String.Format("{0} - {1}%", title, lastProgress * 100 / maxProgress); this.label.Text = ""; cancelButton.Enabled = cancelSupport; backgroundWorker.WorkerSupportsCancellation = cancelSupport; Worker = worker; }
public async Task StartNoUIWork(string title, int totalCount, Func <IAsyncActionWithProgress <uint> > actionFactory) { StartWork?.Invoke(title, (uint)totalCount); var progressHandler = new Progress <uint>((x) => ProgressWork?.Invoke(x)); using (var cancelSource = new CancellationTokenSource(TimeSpan.FromSeconds(30))) { await actionFactory().AsTask(cancelSource.Token, progressHandler); await Task.Delay(500); if (cancelSource.IsCancellationRequested) { CancelWork?.Invoke(); } else { CompleteWork?.Invoke(); } } }
public async Task StartNoUIWork(string title, Func <IAsyncAction> actionFactory) { StartWork?.Invoke(title, 1); using (var cancelSource = new CancellationTokenSource(TimeSpan.FromSeconds(30))) { await actionFactory().AsTask(cancelSource.Token); ProgressWork?.Invoke(1); await Task.Delay(1000); if (cancelSource.IsCancellationRequested) { CancelWork?.Invoke(); } else { CompleteWork?.Invoke(); } } }