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