Is there an integration point into the async/await mechanisms to hook in and know when an async method is started?
Can a custom TaskScheduler provide this hook? A custom SynchronizationContext?
I want to be able to track certain method calls and know which Task (or code) they’re associated with.
Thanks!
According to the Task-based Asynchronous Pattern in section “Task Status”:
That means that you will always start the
Taskas soon as you create it (at least if the factory method implements the TAP, which is true for all methods provided by the .Net framework).If you create and return a “cold” (non-running)
Taskusingnew Task(), there is no clean way to find out if theTask.Start()method was called. You can only check theTaskStatusproperty periodically.