Created
May 7, 2020 09:55
-
-
Save gmunumel/0fd13c1208d57961ab3c4318847a11e2 to your computer and use it in GitHub Desktop.
Async method in C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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