how can i use a time delay in a loop after certain rotation? Suppose:
for(int i = 0 ; i<64;i++)
{
........
}
i want 1 sec delay after ea
Try this simpler version without dependency on async or await or TPL.
Code here
foreach (var item in collection)
{
if (cnt < 50)
{
cnt++;
DoWork(item);
}
else
{
bool stayinLoop = true;
while (stayinLoop)
{
Thread.Sleep(20000);
if (cnt < 30)
{
stayinLoop = false;
DoWork(item);
}
}
}
}
Do work in a separate thread, so that sleep doesn't block you, could be a background worker , Begin , End method of webrequest or optionally an async task or Task.Run()
function DoWork()
//Do work in a sep thread.
cnt--;
)