public static void InfiniteLoopDetector(string Description, Action Action, Action LoopAction = null)
{
using (var Timer = new Timer(4.0 * 1000))
{
bool Cancel = false;
Timer.Elapsed += (sender, e) =>
{
if (!Cancel)
{
Console.WriteLine("InfiniteLoop Detected! : {0} : {1}", Description, e.SignalTime);
if (LoopAction != null)
{
LoopAction();
}
}
};
Timer.AutoReset = false;
Timer.Start();
try
{
Action();
}
finally
{
Cancel = true;
Timer.Enabled = false;
Timer.Stop();
}
}
}
}