Suppose I have a method that is the case, of course, may be my grammar is wrong
Public async void the Run () { Var RST=await (XXX); Var rst2=(XXX); }
Why want to use the first rather than the second, well, asynchronous, but I know that for interface, each request is asynchronous, why even inside the method using asynchronous? I think this is for the sake of asynchronous induction, If is parallel I can understand, wait several method performs complete go down again! It can improve the efficiency of execution, I haven't had enough to understand the Task should be! Hope the great god give a popular hui to parse, thank!!!!!!
CodePudding user response:
My is the interface refers to the WCF, webapi... This kind of interface!
CodePudding user response:
What is await, await is waiting, waiting for the results,
So we don't care about you is what WCF, webapi,
We only care about you want to perform as a result, don't want the result is the second, you want to the results you are the first one Yes, a year ago that a few new to tell you that 5 years want results, put a timer, loop, add a variable, this is a standard answer
And a year later, let their own answer, or standard answer?
CodePudding user response:
I am the second can also returns the result
CodePudding user response:
Await is If XXX is an asynchronous method, Var ss=await (XXX) is asynchronous waiting for the results returned, XXX (); Is executed asynchronously, regardless of the return results Var ss=(XXX). The Result is synchronous get return Result,
For example: Public void Method1 () { Print log 11 An () Print log 22 }
Public async void an () { Code 1 Print log 33 Await (XXX);//XXX () more time-consuming Task available. The Delay () instead of test Print log 44 Code section 2 Print log 55 } Log order for 11 22 33 44 55, that is an execution of the code segment 1 is returned to the first
Suggested that baidu.net awai mechanism
CodePudding user response:
Public async Task ExcuteSql () { //insert data return true; } Public bool ExcuteSql_2 () { //insert data return true; } Public async void InsertData () { Var RST=await ExcuteSql (); Var rst2=ExcuteSql_2 (); }