Why a Async method return type must be void or Task or Task<T>

  • Thread starter Thread starter Sudip_inn
  • Start date Start date
S

Sudip_inn

Guest
See the below code where i change the return type from

public async Task<ResponseContext> DoUpdate(string downloaddate, string listOfID) to

public async ResponseContext DoUpdate(string downloaddate, string listOfID)

then getting error like The return type of an async method must be void, Task or Task<T>

1) Very curious to know an async method return type can anything instead of Task ?

2) what i need to change in code as a result code should compile?

await SqlHelper.ExecuteNonQueryAsync(connection, CommandType.Text, SQL);

ExecuteNonQueryAsync() return Task<int>

that is why async method return type has to be Task<T>

please guide me how to design a function async which can return anything other than Task.

Async sql helper library used and code taken from https://gist.github.com/imranbaloch/10895917

thanks

Continue reading...
 
Back
Top