• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Task.Delay(-1) and GetAwaiter() in Discord bot

Resolved: Task.Delay(-1) and GetAwaiter() in Discord bot

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

Hello guys, just wanna say that im new to programming so i hope who read this post please go easy on me. So i’ve been trying to make a Discord bot and i got confused at the 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.

Answer:

Task.Delay(-1) blocks the process from exiting
Task.GetAwaiter().GetResult() is equivalent to await task and is used when the method cannot be marked with async, in this case, the Main method. this is not recommended read here for more

If you have better answer, please add a comment about this, thank you!

c# discord.net
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How to set consistent decimal separators in R data frame?

26/03/2023

Resolved: How to resolve LNK2001 in c++ projects

26/03/2023

Resolved: How to correctly initialize vector of number in Typescript

26/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.