Skip to content

Instantly share code, notes, and snippets.

@gmunumel
Created May 7, 2020 09:55
Show Gist options
  • Save gmunumel/0fd13c1208d57961ab3c4318847a11e2 to your computer and use it in GitHub Desktop.
Save gmunumel/0fd13c1208d57961ab3c4318847a11e2 to your computer and use it in GitHub Desktop.
Async method in C#
using System;
using System.Threading.Tasks;
namespace Test
{
class Program
{
static void Main(string[] args)
{
TestAsyncAwaitMethods();
Console.WriteLine("Press any key to exit...");
Console.ReadLine();
}
public async static void TestAsyncAwaitMethods()
{
await LongRunningMethod();
}
public static async Task<int> LongRunningMethod()
{
Console.WriteLine("Starting Long Running method...");
await Task.Delay(5000);
Console.WriteLine("End Long Running method...");
return 1;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment