csharp / beginner
Snippet
Simple Asynchronous Method
Asynchronous methods allow tasks to run without blocking the main program execution. The 'async' keyword enables the use of 'await'.
snippet.cs
csharp
1
2
3
4
5
6
7
8
9
using System;using System.Threading.Tasks;public class Process {public async Task RunAsync() {await Task.Delay(500);Console.WriteLine("Finished");}}
Breakdown
1
public async Task RunAsync() {
Defines an asynchronous method that returns a Task.
2
await Task.Delay(500);
Pause execution for 500ms without blocking the thread.