new Program().MainAsync().GetAwaiter().GetResult();i’ve tried to google every parts of the statement and here’s what i got, so the youtuber i watched wants to call the non-static MainAsync in the static Main() and the GetAwaiter().GetResult() will wait for the MainAsync method to be completed.
But i don’t really understand the await Task.Delay(-1) and the GetAwaiter(), hope someone can tell me why he uses GetResult() with await Task.Delay(-1) and what’s GetAwaiter(), thanks.
Task.Delay(-1)blocks the process from exiting
Task.GetAwaiter().GetResult()is equivalent to
awaittask and is used when the method cannot be marked with
async, in this case, the
Mainmethod. this is not recommended read here for more
If you have better answer, please add a comment about this, thank you!