A keyword async is used to qualify a method as an asynchronous method. In other words, if we specify the async keyword in front of a method then we can call this method runs asynchronously. The syntax is:
public async void CallMethod()
{ }
The await keyword is used when we want to call any function asynchronously. The syntax is:
await LongProcess();
The return type for an asynchronous function is Task. In other words we can say that, when it finishes its execution it will complete a Task. Each and every asynchronous method can return these three types of values.
The following example shows how to declare and call a method that returns a Task<TResult> or a Task:
Task<TResult>
async Task<int> GetTaskOfTResult()
{
int hours = 0;
await Task.Delay(0);
return hours;
}
Task<int> returnedTaskTResult = GetTaskOfTResult();
int intResult = await returnedTaskTResult;
Task
async Task GetTask()
{
await Task.Delay(0);
}
Task returnedTask = GetTask();
await returnedTask;
await GetTask();