Task AppendAwaitCompletion(Task theTask) { if (!theTask.IsCompleted) { var updatedTask = theTask.ContinueWith(t => RunningTasks.Remove(t.Id, out _)); return(RunningTasks.AddOrUpdate(theTask.Id, updatedTask, (_, t) => updatedTask)); } return(theTask); }