I would like to understand this scenario a little clearer:
Consider the following code:
frmProgressAsync prog = new frmProgressAsync(true); TaskWithProgress t = new TaskWithProgress("Smoothing CP", true); t.Task = A.ShowMovingAverage(tension,t.Progress) .ContinueWith(prev => { t.ProgressInformation.Report("Smoothing FG"); B.ShowMovingAverage(tension, t.Progress); }); await prog.RunAsync(t);
I have two tasks that I want to run A.ShowMovingAverage and B.ShowMovingAverage . Both return a task.
In the prog.RunAsync() method, I have the following:
public virtual Task RunAsync(TaskWithProgress task) { Show(); TaskIsRunning(); task.ContinueWith(Close(), CancellationToken.None, TaskContinuationOptions.OnlyOnRanToCompletion, this._Scheduler); return task.Task; }
So, I have three tasks that need to be run alternately after completing the previous one.
Now my problem in some cases, the first task is completed almost immediately. When the prog.RunAsync() call is prog.RunAsync() and the final continuation is added to the task, it starts immediately, closing the form.
I can find out if I failed on the last call to ContinueWith() , the state of the RanToCompletion task, but I kind of expect it to continue until reset, so that it continues.
Can someone explain this behavior a little more cleanly? And provide a potential solution so that all tasks (continuations) are completed before the final continuation?