Back In the print window choose "Save as PDF" as the destination
NOTE.CS

async and await

1 topic ยท 28 Nov 2026
1

async and await

C#

async/await runs slow I/O work (web calls, files, database) without blocking the thread. An async method returns Task or Task<T>.

C#
public async Task<string> DownloadAsync(string url)
{
    using var client = new HttpClient();
    string html = await client.GetStringAsync(url);   // thread is free while waiting
    return html;
}

// run several tasks at the same time
var t1 = DownloadAsync("https://a.com");
var t2 = DownloadAsync("https://b.com");
string[] pages = await Task.WhenAll(t1, t2);

Avoid .Result / .Wait() on tasks: they block and can deadlock.