async methods are different from regular methods. Everything that you return from async methods is wrapped in Task .
If you do not return the value (void), it will be wrapped in Task , if you return int , it will be wrapped in Task<int> , etc.
If your asynchronous method needs to return an int , you must mark the type of the returned method as Task<int> , and you will return a plain int , not Task<int> . The compiler will convert int to Task<int> for you.
private async Task<int> MethodName() { await SomethingAsync(); return 42;
Sameway, When you return the Task<object> , the return type of the method should be Task<Task<object>>
public async Task<Task<object>> MethodName() { return Task.FromResult<object>(null);
Since your method returns Task , it should not return any value. Otherwise, it will not compile.
public async Task MethodName() { return;
Keep in mind that an async method without an await statement is not async .
Sriram Sakthivel Aug 07 '14 at 20:37 2014-08-07 20:37
source share