Skip to content

Instantly share code, notes, and snippets.

@embarq
Created August 11, 2016 23:20
Show Gist options
  • Select an option

  • Save embarq/c3cf81f87598bfe9d8a893a93ff8b6a4 to your computer and use it in GitHub Desktop.

Select an option

Save embarq/c3cf81f87598bfe9d8a893a93ff8b6a4 to your computer and use it in GitHub Desktop.
Simple task-based async code descripting
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