TPL に重大なバグを発見したと思います。私はわかりません。私は頭をかきむしるのに多くの時間を費やしましたが、その行動が理解できません。誰でも助けることができますか?
私のシナリオは次のとおりです。
- 簡単なことをするタスクを作成します。例外等はありません。
- ExecuteSynchronously を設定して継続を登録します。同じスレッド上にある必要があります。
- デフォルトのタスクスケジューラ (ThreadPool) でタスクを開始します。開始スレッドは続行し、それを待ちます。
- タスクが開始されます。パスします。
- 継続はタスクと同じスレッドで開始され (前のタスクが完了します!)、無限ループに入ります。
- 待機中のスレッドでは何も起こりません。それ以上行きたくない。待って立ち往生。デバッガーでチェックインしました。タスクは RunToCompletion です。
これが私のコードです。どんな助けにも感謝します!
// note: using new Task() and then Start() to avoid race condition dangerous
// with TaskContinuationOptions.ExecuteSynchronously flag set on continuation.
var task = new Task(() => { /* just return */ });
task.ContinueWith(
_task => { while (true) { } /* never return */ },
TaskContinuationOptions.ExecuteSynchronously);
task.Start(TaskScheduler.Default);
task.Wait(); // a thread hangs here forever even when EnterEndlessLoop is already called.