How to add some delay between each iteration of for loop in C#?

前端 未结 6 1593
轻奢々
轻奢々 2020-12-22 11:32

I\'m working on ASP.NET MVC3 with C#. I want to add some delay between each iteration of for loop.

for(int i=0; i<5; i++)
{
    //some code
    //add dela         


        
6条回答
  •  一整个雨季
    2020-12-22 12:10

    The simplest way is to put the current thread to sleep.

    System.Threading.Thread.Sleep (200);
    

    Remember though, that threads in a web application are very precious resources, and putting one to sleep still keeps the thread busy.

    There is usually no good reason to do this in a web application.
    Whatever problem needs you to do this, can be solved in a better manner.

提交回复
热议问题