1

Judging by the debugger and the "threads" window, both constructs below lead to the same consequences. If we use a non-blocking wait on a worker thread, then it can take up other operations. But what if we use non-blocking wait in the main method, as far as I know the main thread can only execute the main method and cannot switch to other operations outside of this method.

Question: What is the benefit of using a non-blocking wait instead of a blocking wait in the main method?

//await Task.Delay(int.MaxValue); //Main Thread System.Threading.Monitor.Wait
Task.Delay(int.MaxValue).Wait(); //Main Thread System.Threading.Monitor.Wait
  • https://stackoverflow.com/questions/13140523/await-vs-task-wait-deadlock – Ali.Rashidi Dec 13 '22 at 06:20
  • 1
    Suppose you have multiple awaits in main method. Then you would have to move it out to separate method and wait for that separate method in main (or do blocking wait on every async call). With async Main compiler does that for you. So it's just small syntax sugar. – Evk Dec 13 '22 at 06:24
  • @Evk, You can give a good example before and after and we'll see if it counts as an answer. Whatever I'm waiting for in the main thread - non-blocking or blocking, I always do not see the difference. –  Dec 13 '22 at 06:27
  • 2
    The point is - it's just syntax sugar letting you write a bit less code in some situations. It does not provide any benefits in terms of using less threads. – Evk Dec 13 '22 at 06:36

0 Answers0