CKTIS / C#
Task.Delay: practical reference
Task.Delay: practical reference: Task.Delay returns a Task that completes after a delay or cancellation without blocking a thread.
Version: .NET API; verified against .NET 10 reference surface
Syntax
Task.Delay(/* overload-specific arguments */)Task.Delay returns a Task that completes after a delay or cancellation without blocking a thread.
Use it for asynchronous delays and retry logic with CancellationToken.
It is not a precise real-time timer; scheduling can complete it later.
A negative duration other than Infinite throws; zero can return a completed Task.
The complete program actually uses Task.Delay; its exact expected stdout is done.
Examples
using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;
await Task.Delay(TimeSpan.FromMilliseconds(1));
Console.WriteLine("done");
Result
done
The complete program actually uses `Task.Delay`; its exact expected stdout is `done`.