I have a console application which is intended to just keep running until it is killed. Essentially:
<setupCode>
Do
<doProcessing>
Thread.Sleep(<interval>)
Loop
Essentially this will keep running until the user kills it, obviously.
What I'd like to do is replace the Thread.Sleep
call with a wait-condition waiting on either one of two separate events... something like
WaitFor(<intervalPasses> Or <KeyPress>)
so that the app will basically just sleep in the background until the next interval passes, but so that the user can "wake it up" with a keypress. I also want to be able to get the information about the keypress so that e.g. if they pressed Enter I can just start the next iteration without waiting for the timer and if they pressed Escape i would exit the loop altogether, and if they press anything else I would continue waiting for either the timer or one of those two keys.
Either (waiting for a timer)
OR (waiting for a keypress)
would be easy.
Waiting for either (a timer OR a keypress)
I am not sure how to do.
Thanks in advance.