One idea is to parse the input as a DateTime
and then start a new thread that just waits for that time to arrive and then does something. This way your program stays active, but the other code runs at the correct time.
For example:
var dummyText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " +
"Vivamus vitae velit venenatis, malesuada sapien non, ultricies risus. " +
"Quisque magna risus, pulvinar in semper sit amet, tempus suscipit diam. " +
"Cras eget posuere sem, maximus vestibulum tortor. Etiam sodales sit amet " +
"eros non dapibus. Cras pellentesque eleifend risus, quis placerat nulla " +
"vulputate a. Duis erat erat, congue sed justo at, hendrerit varius nunc. ";
Console.Write("What time should the text turn red: ");
var timeInput = DateTime.Parse(Console.ReadLine()); // Enter something like "12:15 PM"
// Start a background task that waits for the specified time to arrive
Task.Factory.StartNew(() =>
{
while (DateTime.Now < timeInput) Thread.Sleep(1000); // Check time every second
Console.ForegroundColor = ConsoleColor.Red; // Change text color
});
// Endless loop that writes out one character of
// text at a time so we can see when it turns red
for(int i = 0; ; i++)
{
if (i == dummyText.Length) i = 0;
Console.Write(dummyText[i]);
Thread.Sleep(150);
}
The above was based on my understanding that you wanted the program to remain actively doing something while waiting for the time. If you just want the whole thing to wait, then you don't need an additional task. All you need is a single line that sleeps until the elapsed time has arrived:
// Pause code execution until the specified time arrives
while (DateTime.Now < timeInput) Thread.Sleep(100);