private async Task BackgroundWorkWithProgressOnUIThreadAsync(string name, Func <IProgressContext, Task <FileOperationContext> > workAsync, Func <FileOperationContext, Task> completeAsync, IProgressContext progress) { ProgressBackgroundEventArgs e = new ProgressBackgroundEventArgs(progress); try { Interlocked.Increment(ref _workerCount); OnOperationStarted(e); FileOperationContext result = await Task.Run(() => workAsync(progress)); await completeAsync(result); } finally { OnOperationCompleted(e); Interlocked.Decrement(ref _workerCount); } }
protected virtual void OnOperationCompleted(ProgressBackgroundEventArgs e) { OperationCompleted?.Invoke(this, e); }