I got something like this:
void func()
{
int a = int.Parse(system.readline.console());
}
But I want this function to finish after 5 seconds for example, even if the user didn't insert anything. How can I do that?
I thought about something like that:
void func()
{
System.Timers.Timer timer = new Timer();
timer.Interval = 5000
timer.Elapsed += SomeFunc;
timer.Start()
int a = int.Parse(system.console.readline());
}
void SomeFunc(object sender, EventArgs args)
{
Thread.CurrentThread.Abort();
}
But it looks too ugly. In addition, I don't really want to abort all the threads, just break this function. I don't want to create another thread only for this function.