I would like to stop a function after a fixed execution time. Here i've written an sample for you:
Stopwatch timer = new Stopwatch();
timer.Start();
while (timer.Elapsed.TotalSeconds < timeLimite)
{
//my functions
}
timer.Stop();
In my own test, it does not limit the execution time inside my functions. In other words, it tests the stopping criterion before and after the execution of my functions but does not interrupt the algorithm inside "my functions".