The memory consumption in methods Task.Delay and Thread.Sleep is different, I used both and the answer have a big performance difference. Does Anyone know why?
The code with Thread
private void EncerrarWorkers()
{
foreach (BackgroundWorker worker in Workers)
{
worker.CancelAsync();
}
//Encerra os bots
Model.BotsClose();
for (int indexRobo = 0; indexRobo < Workers.Count(); indexRobo++)
{
if (Model.IsBotClosed(indexRobo))
continue;
Thread.Sleep(5000);
indexRobo--;
}
}
The code With Task
private void EncerrarWorkers()
{
foreach (BackgroundWorker worker in Workers)
{
worker.CancelAsync();
}
//Encerra os bots
Model.BotsClose();
for (int indexRobo = 0; indexRobo < Workers.Count(); indexRobo++)
{
if (Model.IsBotClosed(indexRobo))
continue;
Task.Delay(5000);
indexRobo--;
}
}
A both are contained in a method of Windows Form.
The performance difference in utilize the block of code: enter image description here