I'm trying to understand async/await and read the source code of AsyncMethodBuilder. I thought there must be some code like xxx.Wait() or xxx.WaitOnce() waiting for a task to be completed.
However, I didn't find such code in class AsyncMethodBuilder.
system\runtime\compilerservices\AsyncMethodBuilder.cs https://referencesource.microsoft.com/#mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs,96
So I keep digging, tried to read the source code of Task, TaskScheduler, ThreadPoolTaskScheduler, ThreadPool.
Finally I got class _ThreadPoolWaitCallback, but didn't find any caller.
https://referencesource.microsoft.com/#mscorlib/system/threading/threadpool.cs,d7b8a78b4dd14fd0
internal static class _ThreadPoolWaitCallback
{
[System.Security.SecurityCritical]
static internal bool PerformWaitCallback()
{
return ThreadPoolWorkQueue.Dispatch();
}
}
Another possible code is in class SynchronizationContext, method SetWaitNotificationRequired()
protected void SetWaitNotificationRequired()
{
...
RuntimeHelpers.PrepareDelegate(new WaitDelegate(this.Wait));
...
But I didn't know what RuntimeHelpers.PrepareDelegate is doing, which is a native method.
Please give some advice. Is there a Wait? And if it is, where it is?