← Back to C# Course | Chapter 13: Async Programming | Lesson 1 of 6

async / await Basics

In this page:

  1. async / await Basics

async / await Basics

async marks a method as asynchronous, allowing it to use await to pause execution at a slow operation without blocking the calling thread. Control returns to the caller while the awaited operation runs, then resumes the method when it completes. This keeps applications responsive during I/O-bound work like network or file access.

Note: An async method should return Task or Task<T> (or void only for event handlers), never block synchronously inside it.

Example: async / await Basics

markup
using System;
using System.Threading.Tasks;

class Program
{
    static async Task<int> ComputeAsync()
    {
        await Task.Delay(100);
        return 42;
    }

    static async Task Main(string[] args)
    {
        Console.WriteLine("Starting...");
        int result = await ComputeAsync();
        Console.WriteLine($"Result: {result}");
    }
}
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.