How does running several tasks asynchronously on UI thread using async/await work?

前端 未结 3 1281
旧时难觅i
旧时难觅i 2020-12-15 10:58

I\'ve read (and used) async/await quite a lot for some time now but I still have one question I can\'t get an answer to. Say I have this code.

private async          


        
3条回答
  •  不思量自难忘°
    2020-12-15 11:09

    When UI thread calls await it starts the async operation and returns immediately. When the async operation completes, it notifies a thread from the thread pool but the internal implementation of async await dispatches the execution to the UI thread which will continue the execution of the code after the await.

    The Dispatch is implemented by means of SynchronizationContext which in turn calls System.Windows.Forms.Control.BeginInvoke.

    CLR via C# (4th Edition) (Developer Reference) 4th Edition by Jeffrey Richter page 749

    Actually, Jeffrey worked with MS to implement the async/await inspired by his AsyncEnumerator

提交回复
热议问题