V
V
VitalyaRusher2018-10-01 08:55:41
C++ / C#
VitalyaRusher, 2018-10-01 08:55:41

How to make a time limit on user input?

How to make an input timer so that when the time runs out, a message is displayed.
On the example of games when a choice is given at a time. Is it possible to do it in c#? It is in the console application and not in Windows.Forms.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri, 2018-10-01
@VitalyaRusher

int minutes = 1;
while (true)
{
   if (Console.KeyAvailable)
   {
        ConsoleKeyInfo c = Console.ReadKey(true);
    if (c.Key == ConsoleKey.Enter)
    {
            break;
    }
   }
   Thread.Sleep(1000);
   if (minutes++ > 10)
   {
    throw;
   }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question