条件付きでタスクを実行したい場合があります。次のような拡張メソッドを使用します。
public static class MyTaskExtension{
private static Task theEmptyTask = Task.Factory.StartNew(() => {}); //This is the question
public static Task ContinueWith(this Task task, Task continuationTask, Func<bool> condition)
{
if condition(){
... do the work
}
return theEmptyTask;
}
}
私の予想では、theEmptyTask は既に完了しているので、基本的に何もしたくない場合は、null または新しい空のタスクではなく、このタスクを返すだけです。
このアプローチには何らかの不具合があるはずだと感じています。誰でもそれを見ることができますか?