要实现的功能是 : 每隔10分钟启动程序, 启动后做一些消耗时间的操作, 但不管这些操作需要多少时间(一般不会超过10分钟) , 程序仍然准时在10分钟后启动 。

while (true)
{
    int startTime = Environment.TickCount
    File.AppendAllText(strCurrentPath + @"\TimerLog.txt", "begin " + DateTime.Now.ToString() + "\r\n");

    //do some work which will spent time
    spendTime();

    int timeBeforeSleep = Environment.TickCount
    int consumedTime = timeBeforeSleep - startTime
    Thread.Sleep(600000 - consumedTime);               // sleep  10 mins

} // while

 

详见

http://stackoverflow.com/questions/21398097/how-to-set-exactly-time-period

 

相关文章:

  • 2022-12-23
  • 2022-01-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-26
  • 2021-09-08
  • 2021-04-22
猜你喜欢
  • 2022-01-20
  • 2022-01-02
  • 2022-01-08
  • 2022-12-23
  • 2022-02-12
  • 2022-12-23
  • 2021-12-06
相关资源
相似解决方案