This is an interesting question I have, so I ask you to hear me out. No, I'm not just going to ask "how do I do this" and hope someone will give me code.
I've been programming for a long time and am beginning work on a side-project, a text-based game.
Without going into details, the game needs commands (a Console.ReadLine()
sort of situation) but also needs timer-based systems (say, for instance, decreasing a variable energy
every 10 seconds)
I've racked my brain about how to accomplish this, but came up empty handed.
My best guess is using asynchronous functions but I don't fully understand those and they don't seem like they will accomplish what I'm after.
TL;DR I want to be able to use Console.ReadLine()
and also increase/decrease a variable every n
milliseconds (even while waiting for the console input).
I think threading might be a way to do it, but that seems excessive for a [relatively] simple usecase.
Can anyone provide insight about how to accomplish this?
Thanks in advance.
EDIT: Ideally this would be a general answer that could apply to running any time consuming task in the background, while keeping the console available to read lines, print output, etc.