Created
August 11, 2016 23:20
-
-
Save embarq/c3cf81f87598bfe9d8a893a93ff8b6a4 to your computer and use it in GitHub Desktop.
Simple task-based async code descripting
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; | |
| using System.Threading.Tasks; | |
| namespace Async | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| StartFirstLongTask(); | |
| StartSecondLongTask(); | |
| Console.ReadLine(); | |
| } | |
| static async void StartFirstLongTask() | |
| { | |
| string result = await FirstLongTask(); | |
| Thread.Sleep(3000); | |
| Console.WriteLine($"An end of the {result}"); | |
| } | |
| static async void StartSecondLongTask() | |
| { | |
| string result = await SecondLongTask(); | |
| Thread.Sleep(1000); | |
| Console.WriteLine($"An end of the {result}"); | |
| } | |
| static Task<string> FirstLongTask() | |
| { | |
| return Task.Run(() => "first long task."); | |
| } | |
| static Task<string> SecondLongTask() | |
| { | |
| return Task.Run(() => "second long task."); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment