csharp / beginner
Snippet
Asynchronous Task Basics
Asynchronous programming allows your application to remain responsive by offloading long-running operations. The 'async' modifier enables the 'await' keyword inside a method.
snippet.cs
csharp
1
2
3
4
5
public async System.Threading.Tasks.Task<int> GetDataAsync(){await System.Threading.Tasks.Task.Delay(1000);return 42;}
Breakdown
1
public async System.Threading.Tasks.Task<int> GetDataAsync()
Declares an asynchronous method that returns a Task containing an integer.
2
await System.Threading.Tasks.Task.Delay(1000);
Pauses execution asynchronously for 1000 milliseconds without blocking the thread.