Lesson 5 of 8Article18 min
Async and Await
async/await simplifies non-blocking code. It is essential for API calls, file I/O, and high-throughput server endpoints.
Asynchronous programming model
async/await simplifies non-blocking code. It is essential for API calls, file I/O, and high-throughput server endpoints.
Task-based async example
Awaiting asynchronous work
using System.Net.Http;
static async Task<string> FetchAsync(string url)
{
using var client = new HttpClient();
return await client.GetStringAsync(url);
}
var content = await FetchAsync("https://example.com");
Console.WriteLine(content.Length);