Skip to content

Instantly share code, notes, and snippets.

@v2m
Created June 18, 2013 00:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save v2m/5801835 to your computer and use it in GitHub Desktop.
Save v2m/5801835 to your computer and use it in GitHub Desktop.
class Program
{
static void Main(string[] args)
{
Run().Wait();
}
static async Task Run()
{
var tcs = new TaskCompletionSource<object>();
Task t1 = null;
Console.WriteLine("1:" + Environment.CurrentManagedThreadId);
t1 = Task.Factory.StartNew(() =>
{
Console.WriteLine("2:" + Environment.CurrentManagedThreadId);
System.Threading.Thread.Sleep(1000);
tcs.SetResult(null);
}
);
Console.WriteLine("3:" + Environment.CurrentManagedThreadId);
await tcs.Task;
Console.WriteLine("4:" + Environment.CurrentManagedThreadId);
t1.Wait();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment