Tasks only complete one time. When you attach a continuation, you are creating a new task that starts when the antecedent task completes. So, I believe the problem you're seeing is that RunAsync
is attaching the Close
continuation but not doing anything with the continuation task; consider task.Task = task.ContinueWith(Close(), ...)
.
However, I recommend that you use await
instead of ContinueWith
. I find that usually clarifies the code and makes it easier to understand.
frmProgressAsync prog = new frmProgressAsync(true);
TaskWithProgress t = new TaskWithProgress("Smoothing CP", true);
t.Task = ShowMovingAveragesAsync(A, B, tension, t.Progress);
await prog.RunAsync(t);
private async Task ShowMovingAveragesAsync(TA A, TA B, TT tession, IProgress<string> progress)
{
progress.Report("Smoothing FG");
await A.ShowMovingAverageAsync(tension, progress);
progress.Report("Smoothing FG");
await B.ShowMovingAverageAsync(tension, progress);
}
public virtual async Task RunAsync(TaskWithProgress task)
{
Show();
TaskIsRunning();
await task;
Close();
}