Skip to content

Instantly share code, notes, and snippets.

@bleis-tift
Created October 19, 2016 13:20
Show Gist options
  • Save bleis-tift/3c0c520b95c3a062e71972f5355db542 to your computer and use it in GitHub Desktop.
Save bleis-tift/3c0c520b95c3a062e71972f5355db542 to your computer and use it in GitHub Desktop.
AsyncTaskMethodBuilderのStartが呼び出される
stateMachine(生成されるクラス)のMoveNextが呼び出される
非同期メソッドの呼び出し結果に対してGetAwaiterが呼び出される
AsyncTaskMethodBuilderのAwaitUnsafeOnCompletedが呼び出される
AwaitUnsafeOnCompletedが呼び出される
GetCompletionActionが呼び出される
AsyncMethodBuilder.MoveNextRunnerが生成される(ここにstateMachineのインスタンスが渡される)
AsyncMethodBuilder.MoveNextRunnerのRunが返される(中でstateMachineのMoveNextを呼び出している)
awaiterのUnsafeOnCompletedが返されたactionを渡して呼び出される
ここからはAwaiter次第だが、TaskAwaiterを例にする
TaskAwaiter.OnCompletedInternalを呼び出す
SetContinuationAwaitを呼び出す
SynchronizationContextAwaitTaskContinuationを生成
SynchronizationContextAwaitTaskContinuation.Runを呼び出す
RunCallbackを呼び出す
コンテキストがキャプチャされていればcallbackを実行、そうでなければExecutionContext.Runを呼び出す
どちらにしても結局stateMachineのMoveNextが呼び出される
@bleis-tift
Copy link
Author

SynchronizationContext.Current のPostをSendを呼び出すようなものに設定してもスタックがあふれない

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment