C# › Asynchronous Programming

What is the difference between the async and await keywords in C#, and how do they work together?

Beginner

Answer

async marks a method as containing asynchronous logic, enabling the use of await inside it, but by itself does not make the method run on a background thread -- await is what actually pauses execution of the async method at that specific point until the awaited Task completes, WITHOUT blocking the calling thread, letting the application remain responsive while the operation (an API call, file read, database query) finishes in the background; once the awaited task completes, execution resumes from exactly where it left off.
public async Task<string> GetDataAsync() {
    await Task.Delay(2000); // simulates a slow I/O operation, without blocking the thread
    return "Data received";
}

public async Task ShowData() {
    string data = await GetDataAsync(); // pauses here until GetDataAsync completes
    Console.WriteLine(data);
}
Real-world example A desktop application fetching weather data from a remote API uses async/await so the UI thread stays responsive (the window can still be dragged/resized) while the three-second network call completes in the background, rather than freezing entirely as a synchronous, blocking call would.

Common follow-ups: What happens if you forget the await keyword in front of an async method call?;Why does calling .Result or .Wait() on a Task risk a deadlock in certain contexts?