Having long running Task, something like this
Task.Factory.StartNew(() =>
{
var step = 0;
while (true)
{
Task.Delay(100).Wait();
Console.WriteLine(step);
step++;
if (step > MaxStep)
{
return;
}
}
}, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default);
In the same application there are lots of Tasks with API calls executing and when, sometimes that API calls are slowing down, this main long running task having disturbance, taking more than 150 milliseconds to the next step. How can I make this task flawless? Any ideas?
Tried to use Thread on place of Task, same result. Wanted to change API calls to async but too much refactoring in old code, scared to touch it. Artifically wrapped methods with API calls to async methods but same result.