Back to course

Asynchronous Programming: Async and Await

C# Zero to Hero: Comprehensive Programming Masterclass

Async and Await

Asynchronous programming avoids blocking the main thread, making your applications responsive.

Example

csharp public async Task GetDataAsync() { await Task.Delay(2000); // Simulate work return "Data loaded"; }

Task represents the work to be done. await pauses the execution until the task finishes without freezing the UI.