Created
October 10, 2022 22:31
-
-
Save to11mtm/eb6cdc51e864e6b1bd62192f87614756 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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