How to execute the loop for specific time

后端 未结 7 1036
心在旅途
心在旅途 2020-12-05 13:37

How can i execute the a particluar loop for specified time

Timeinsecond = 600

int time = 0;
while (Timeinsecond > time)
{
   // do something here
}
         


        
7条回答
  •  遥遥无期
    2020-12-05 14:16

    May be the following will help:

      Stopwatch s = new Stopwatch();
      s.Start();
      while (s.Elapsed < TimeSpan.FromSeconds(600)) 
      {
          //
      }
    
      s.Stop();
    

提交回复
热议问题