Untitled
unknown
plain_text
a year ago
864 B
7
Indexable
using System;
using System.Threading.Tasks;
namespace DSA_EASY
{
class AsyncExample
{
static async Task Main(string[] args) // Main method must be async to use await
{
Console.WriteLine("main start");
await new DSA_EASY.AsyncExample().Method1Async(); // Await the async method
Console.WriteLine("main end");
}
public async Task Method1Async()
{
Console.WriteLine("Method1 started.");
await Method2Async();
Console.WriteLine("Method1 completed.");
}
public async Task Method2Async()
{
Console.WriteLine("Method2 started.");
await Task.Delay(20000); // Simulates an asynchronous delay
Console.WriteLine("Method2 completed.");
}
}
}
Editor is loading...
Leave a Comment