the different is that the function with the await
is wait to finish first his job before return. Now on web page that I make some test, no one from that two functions blocks the running of code, and they continues to run on a thread.
public async Task<IActionResult> ExampleCall([FromBody]ExampleObj model)
{
// Call some lower level function...
// ***Here is not return until this function is finish first.***
var result = await LowerLevelCall(model);
return result;
}
Lets look inside.... I make two functions similar to yours
public static async Task<bool> Task1()
{
await Task.Delay(10000);
return true;
}
public static async Task<bool> Task2()
{
Task.Delay(10000);
return true;
}
The final code on this two is a lot different.
With await
private void MoveNext()
{
bool flag;
int num = this.<>1__state;
try
{
TaskAwaiter awaiter;
if (num != 0)
{
awaiter = Task.Delay(0x2710).GetAwaiter();
if (!awaiter.IsCompleted)
{
this.<>1__state = num = 0;
this.<>u__1 = awaiter;
cTestClass.<Task1>d__0 stateMachine = this;
this.<>t__builder.AwaitUnsafeOnCompleted<TaskAwaiter, cTestClass.<Task1>d__0>(ref awaiter, ref stateMachine);
return;
}
}
else
{
awaiter = this.<>u__1;
this.<>u__1 = new TaskAwaiter();
this.<>1__state = num = -1;
}
awaiter.GetResult();
awaiter = new TaskAwaiter();
flag = true;
}
catch (Exception exception)
{
this.<>1__state = -2;
this.<>t__builder.SetException(exception);
return;
}
this.<>1__state = -2;
this.<>t__builder.SetResult(flag);
}
with out
// MoveNext is the name of warped function that call the thread.
private void MoveNext()
{
bool flag;
int num = this.<>1__state;
try
{
Task.Delay(0x2710);
flag = true;
}
catch (Exception exception)
{
this.<>1__state = -2;
this.<>t__builder.SetException(exception);
return;
}
this.<>1__state = -2;
this.<>t__builder.SetResult(flag);
}
Some comments
All this inline functionality of asp.net have the purpose to simplify and help for asynchronous do thread work. Have a point on desktop programming that is help to not hold the "draw" message from windows to your program, but on asp.net did not have many effects that are visible, and add a lot of overhead. If you don't know exactly how the multitask will be used it may lead on more delay than help because all are happened on server, not on client that no need this kind of multitask.