© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
3 replies
eid

await-work in thread class is different from await-work in task class?

var thread = new Thread(async () =>
{
Console.WriteLine($"Thread before await: {Thread.CurrentThread.ManagedThreadId}");
await Task.Delay(500); // Simulate asynchronous delay
Console.WriteLine($"Thread after await: {Thread.CurrentThread.ManagedThreadId}");
});
thread.Start();
thread.Join(); // Wait for the thread to complete

// Using Task
Task.Run(async () =>
{
Console.WriteLine($"Task before await: {Thread.CurrentThread.ManagedThreadId}");
await Task.Delay(500); // Simulate asynchronous delay
Console.WriteLine($"Task after await: {Thread.CurrentThread.ManagedThreadId}");
}).Wait(); // Wait for the task to complete
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ async/await Task in an AWS Lambda
C#CC# / help
3y ago
❔ ✅ Baffled by Async-Await and Task
C#CC# / help
4y ago
Can i use async/await in class constructors?
C#CC# / help
2y ago