Created
March 9, 2018 11:14
-
-
Save hrkrx/7c6e6866e300e43a2c36b95fb6e96cd4 to your computer and use it in GitHub Desktop.
This file contains 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) | |
{ | |
Console.WriteLine("Starting..."); | |
MainAsync().GetAwaiter().GetResult(); | |
} | |
static async Task MainAsync() | |
{ | |
bool isDone = false; | |
Task.Run(async () => { | |
Console.WriteLine("Task1 started"); | |
while (!isDone) { | |
await Task.Delay(1); | |
Console.WriteLine("Inside Task1: " + isDone); | |
} | |
Console.WriteLine("Task1 finished"); | |
}); | |
await Task.Run(async () => { | |
Console.WriteLine("Task2 started"); | |
isDone = false; | |
await Task.Delay(10); | |
isDone = true; | |
Console.WriteLine("Task2 finished"); | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment