C# ADVANCEDChapter 5 · C# Advanced
Async and Await in C#
Use async and await with Task to write asynchronous, non-blocking code. This keeps your apps responsive during heavy operations like network calls.
Worked example
using System;
using System.Threading.Tasks;
class Program {
static async Task Main() {
string data = await FetchDataAsync();
Console.WriteLine(data);
}
static async Task<string> FetchDataAsync() {
await Task.Delay(100);
return "clouds loaded";
}
}How it reads
- async Task defines an asynchronous method returning a Task object
- await pauses execution of the current method without blocking

Cloud tip: Asynchronous methods should always end with the suffix 'Async' by convention.


