c#程序实现定时唤醒

要实现的功能是 : 每隔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

 

posted on 2014-01-28 14:48  齐文宣  阅读(794)  评论(0编辑  收藏  举报

导航