Created
February 8, 2017 04:02
-
-
Save davidfowl/decbf2441ecf6a672538f66cd531b08b to your computer and use it in GitHub Desktop.
Async quiz: How many threads are used? What does it print?
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.Runtime.CompilerServices; | |
using System.Threading.Tasks; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var tcs = new TaskCompletionSource<object>(); | |
var task = SomethingAsync(tcs); | |
Console.WriteLine("Hello"); | |
tcs.TrySetResult(null); | |
task.Wait(); | |
} | |
private static async Task SomethingAsync(TaskCompletionSource<object> tcs) | |
{ | |
await tcs.Task; | |
Console.WriteLine("World"); | |
} | |
} |
@Tuatan, try to add additional Console.Readline() methods after each line and check number of threads in Windows Task Manager
After this try same under linux :)
Sure things like http://mattwarren.org/2017/02/07/The-68-things-the-CLR-does-before-executing-a-single-line-of-your-code/ must be here
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
1 and "Hello World"