Async/ Await: why does the code that follows await is also executed on the background thread and not on the original primary thread?
问题 Below is my code: class Program { static async Task Main(string[] args) { Console.WriteLine(Thread.CurrentThread.ManagedThreadId); string message = await DoWorkAsync(); Console.WriteLine(Thread.CurrentThread.ManagedThreadId); Console.WriteLine(message); } static async Task<string> DoWorkAsync() { return await Task.Run(() => { Thread.Sleep(3_000); return "Done with work!"; }); } } and the output is 1 // after 3 secs 3 Done with work! so you can see the main thread(id is 1) changed to worker