How can I catch TimeoutException
?
I want to catch TimeoutException
after 3 secs.
But after 3 secs it prints out TimeoutException
whereas It's too long. Timeout!
is expected.
With console application
it doesn't catch TimeoutException
.
public static void work()
{
Thread.Sleep(3000);
Console.WriteLine("TimeoutException");
throw new TimeoutException();
}
public static void Main(string[] args)
{
try
{
ThreadStart th = new ThreadStart(work);
Thread t = new Thread(th);
t.Start();
//Execute SearchProgram
t.Abort();
}
catch (ThreadInterruptedException)
{
Console.WriteLine("It's too long. Timeout!");
}
Console.WriteLine("Result : ~~~");
}