-
Notifications
You must be signed in to change notification settings - Fork 2
CSharp Async SimpleTaskAwait
Joe Care edited this page Dec 22, 2025
·
1 revision
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:
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:
-
DoWorkAsyncis anasync Taskmethod that usesawait Task.Delay. -
Mainis alsoasync Taskso it canawaitthe work.
- Combine this pattern with real I/O operations as shown in
CSharp-AsyncAwait-Basics.mdandLesson09.12.2025.md(HTTP example). - Study error handling patterns with
try/catchfromCSharp-Exceptions-TryCatch.mdin async code.