✅ Why won't the loop loop?
I'm using the console template + old coding style. I expected the game to run in a loop, however the game exited. The code above is my Program.cs btw
10 Replies
starting a task does not wait for that task to finish (and it was already started anyway)
so how am i gonna workaround ts?
You’re creating the Task and starting it immediately with Task.Factory.StartNew.
That means the loop is already running by the time the Game constructor finishes.
2 options
Option 1: Use Task.Factory.StartNew (don’t call Start())
or
Option 2: Use new Task(...) and then Start()
ok
no it wont work
Never use
new Task
.
And you’re still not waiting on the task. As a background thing, the runtime doesn’t wait for them to finish before exiting.
Use an async signature for Main, and await the Task.Unknown User•4d ago
Message Not Public
Sign In & Join Server To View
out of curiosity, why should you never use
new Task
?I mean, mostly there’s no reason to. StartNew and Run cover the cases fine.
Unknown User•4d ago
Message Not Public
Sign In & Join Server To View
alr
ikr
just didnt know it's applicable for Main(string[])
and how will it change
thank yall though