I do not understand , i have seen that there are many methods provided by the .Net Framework
that have both async
and non-async
variants.
My question is what advantage does an async
method provide me given the following constraints:
- I will not fetch the Task.Result
multiple times in the same method
- I am not using CPU-bound
tasks (Task.Run(...)
)
I am in a MVC
controller and i want to process a post
request:
[HttPost]
[Route(..)]
public async Task DoSomething(MyModel model)
{
var asyncResult=await NETMethodAsync(model); //PostAsync,WriteAsync....
var nonAsyncResult= NETMethod(model); //Post,Write,....etc..
return result;
}
In this case i will use the result
only once in my method and i will not demand it multiple times ( where await
would just give me the completed task-result) what is the difference ?
I am basically creating a StateMachine
in my MethodAsync
for what?
I could do the operation non-async
faster i suppose.
If i am not delegating the method on a separate Task
(like below) why would i use the async
version ?
I am asking because even the MVC Controller
templates by default provide all CRUD
operations using the async
versions.
Task tsk=Task.Run(async()=> await MethodAsync() );
P.S In my scenario is it something that i missed.Is it faster to use the async
(that internally spins a state-machine) ,then the non-async version ?