Skip to content

CSharp Async SimpleTaskAwait

Joe Care edited this page Dec 22, 2025 · 1 revision

C# Async: Simple Task and await Example

This lesson shows a minimal example of using Task and await to run asynchronous work.

Related wiki pages:

  • Async basics: CSharp-AsyncAwait-Basics.md
  • Tasks and Task.Run: CSharp-Async-Tasks-TaskRun.md

Official docs:


1. Example: simulate work asynchronously

using System;
using System.Threading.Tasks;

public class AsyncExample
{
    private static async Task DoWorkAsync()
    {
        Console.WriteLine("Starting DoWorkAsync...");
        await Task.Delay(2000); // simulate long-running work
        Console.WriteLine("DoWorkAsync completed.");
    }

    public static async Task Main(string[] args)
    {
        await DoWorkAsync();
        Console.WriteLine("Asynchronous example completed.");
    }
}

Key points:

  • DoWorkAsync is an async Task method that uses await Task.Delay.
  • Main is also async Task so it can await the work.

2. Next steps

  • Combine this pattern with real I/O operations as shown in CSharp-AsyncAwait-Basics.md and Lesson09.12.2025.md (HTTP example).
  • Study error handling patterns with try/catch from CSharp-Exceptions-TryCatch.md in async code.

Clone this wiki locally