Suppose my console program performs multiple lengthy tasks. Between these tasks, I’d like it to pause – either for a few seconds or until any key gets pressed. (Whichever comes first.)
These criteria are easy to check on their own, but they refuse to get along when I try combining them: Either the timing mechanism pauses for a few seconds before ReadKey starts, or Readkey blocks out the thread entirely until satisfied. How can I satisfy both conditions?
One way to do this in C# 4.0: