Skip to content
dreamcode
dreamcode
Map
Async & await
Lesson 17 of 21
+15 XP on finish
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.

Check your understanding

0 / 2

Answer all 2 to complete this lesson and earn 15 XP.

  1. 1. What return type should a C# async method return if it does not return any data value?
  2. 2. What keyword is placed before a Task call to yield control back to the caller while it finishes?
Answer every question to unlock the next lesson.