await Task.Yield (); super-simple to understand!

await Task.Yield();//1
var data = LoadData();//2
await Task.Run(() => Do(data));//3

Similar to the above code:

Task.Run(() => { }).ContinueWith(t => Do(LoadData()));

Meaning: loadData if takes a long time then the above code will produce obstruction, in order not to block LoadData specifically added await Task.Yield (); 

Means: first ranked teams.

再来看注释:Creates an awaitable task that asynchronously yields back to the current context when awaited.

Create an asynchronous empty, this quest for waiting.

Means: create an empty task, and then wait for, wait behind the code will be compiled into subsequent tasks , so put was supposed to be the main task of doing live into an empty task  of follow-up mission in.

So that the main task tinkling child ... gets the job done.

 

 

Guess you like

Origin www.cnblogs.com/zhuwansu/p/11230924.html