Skip to content

Instantly share code, notes, and snippets.

@to11mtm
Created October 10, 2022 22:31
Show Gist options
  • Select an option

  • Save to11mtm/eb6cdc51e864e6b1bd62192f87614756 to your computer and use it in GitHub Desktop.

Select an option

Save to11mtm/eb6cdc51e864e6b1bd62192f87614756 to your computer and use it in GitHub Desktop.
async Task Main()
{
var tcs = new TaskCompletionSource();
var t = new Thread(async () =>
{
try
{
for (int i = 0; i < 2; i++)
{
Thread.CurrentThread.IsThreadPoolThread.Dump();
Thread.CurrentThread.Name.Dump("Before call " +(i+1));
//Compare output for await vs Wait.
//I left the ConfigureAwait False in for posterity,
//but really makes no difference.
//await MyTask().ConfigureAwait(false);
//await MyTask();
MyTask().Wait();
}
Thread.CurrentThread.Name.Dump("After Call");
}
catch
{
}
tcs.SetResult();
});
t.Name = "test";
t.Start();
t.Join();
"Join Done".Dump("After Join");
await tcs.Task;
}
async Task MyTask()
{
Thread.CurrentThread.Name.Dump("in myTask before await");
await Task.Delay(500);
Thread.CurrentThread.Name.Dump("in myTask after await");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment