I would like to repeat a function until the function has no timeout. The function should return something but if it takes too long the function call should be repeated. This is what I have:
var task = Task.Run(() => main.getPlaces(field));
while (true)
{
if (task.Wait(TimeSpan.FromSeconds(1)))
{
field = task.Result;
break;
} else
{
task = Task.Run(() => main.getPlaces(field));
continue;
}
}
It seems like the function isn't recalled with this setup. The console output just gets slower and slower.