Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Async quiz: How many threads are used? What does it print?
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

This comment has been minimized.

Copy link

Tuatan commented Mar 17, 2017

1 and "Hello World"

@Roman-Blinkov

This comment has been minimized.

Copy link

Roman-Blinkov commented Apr 28, 2017

@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
You can’t perform that action at this time.