.NET by Patrik
Task.Delay Method creates a task that will complete after a time delay.
Task.Delayis generally preferred when working with asynchronous programming using
- It returns a
Taskthat represents a time delay.
- It doesn't block the calling thread. Instead, it allows the thread to be released and continue with other work while waiting for the specified time to elapse.
- It's more suitable for scenarios where you want to introduce a delay without blocking the execution of the current method or freezing the user interface in GUI applications.
async Task MyMethod()
// Do something before the delay
await Task.Delay(1000); // Delay for 1000 milliseconds (1 second)
// Do something after the delay
Leave a Comment
All fields are required. Your email address will not be published.