I'm trying to understand async await behavior and in particular how it affects the main thread, so my question is related to below code:
static async Task Main(string[] args)
{
await LongAction();
}
static Task LongAction() => Task.Delay(10000);
what will happen with the main thread when LongAction is being executed. As I understand, if the the caller thread is not the main (let's call it thread2), during the time when awaitable operation is in play, this thread (thread2) will be returned to the ThreadPool (with default task scheduler). But can it happen with the main thread (it doesn't looks so, since initially it wasn't taken from TP)? What if the main thread is UI thread with thread context?
main()method, the caller must have a loop, and loops until the Task (returned by the main) is marked as completed. In the example, the method is marked as async, so it will turn into a statemachine. When the last state is completed, it terminates the loop.loopdo you mean?