A quick introduction is provided on the Async feature introduced in C# 5. Async feature is designed to help asynchronous programming to make applications more responsive in activities that are potentially slow or delayed.
What Is Async Feature?
Async feature is a new feature introduced in C# 5.
Async feature is designed to help asynchronous programming to make applications
more responsive in activities that are potentially slow or delayed.
Without asynchronous programming consideration, such applications
For example, if you have GUI application with thread to accesses the web,
you can make the web request asynchronously and put the thread in suspended mode
while waiting for the response from the web. This frees up CPU resources for
other threads to respond to user's UI activities with better response time.
According to C# 5 specification, Async Feature uses two keywords:
async - A method modifier to declare an async function.
Execution of an async function can be suspended by an "await" expression
in its body, and resumed later.
await - An operator on an awaitable expression to express an await operation,
which can only be used in an async function.
Evaluation of an await operation is to suspend the current thread until the await
operand to finish.
Below is a diagram provided by Microsoft showing the execution flow of an
async function with an await expression: