Given the discussions so far in comments, my first recommendation is definitely to create a System Tray application for this. This would allow for user interaction and notifications without having to keep a Console window on the desktop.
Failing that, you could perhaps implement something like a "game loop" in your console. How "real time" do the statistics need to be? One-second delayed maybe? Something like this:
while (true)
{
Thread.Sleep(1000);
DisplayCurrentStats();
}
This would pause the main thread (not always recommended, but it is the UI that you're trying to keep open here) and then output the display every second. (If the output is already handled by something else and for whatever reasons shouldn't be moved here, just ignore that part.)
You'd probably still want some way of breaking out of the whole thing. Maybe an escape input:
while (true)
{
Thread.Sleep(1000);
DisplayCurrentStats();
var escape = Console.Read();
if (IsEscapeCharacter(escape))
break;
}
OutputGoodByeMessage();
In the IsEscapeCharacter()
method you can check if the character read from the Console (if there was one) matches the expected "escape" character. (The esc
key seems like a standard choice, though for obscurity you can use anything else in order to try to prevent "accidental escape.") This would allow you to terminate the application cleanly if you need to.
It's still at 1-second delay increments, which isn't ideal. Though even at 1/10-second it's still spending the vast majority of its time sleeping (that is, not consuming computing resources) while providing some decent UI responsiveness (who complains about a 1/10-second delay?):
Thread.Sleep(100);