CSharp · Console
using System;
using System.Threading;
public class Program
{
public static void Main()
{
tryMethod();
using (CancellationTokenSource cts = new CancellationTokenSource(5000))
{
cts.Token.Register(() =>
{
Console.WriteLine("This would throw your Exception...");
}
);
while (!cts.IsCancellationRequested)
{
tryMethod();
}
}
}
public static void tryMethod()
{
Console.Write("Sleeping...");
Thread.Sleep(200);
Console.WriteLine(" slept 200");
}
}