首页 > 其他 > 详细

c#程序实现定时唤醒

时间:2014-01-28 21:08:14      阅读:386      评论:0      收藏:0      [点我收藏+]

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

bubuko.com,布布扣
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
bubuko.com,布布扣

 

详见

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

c#程序实现定时唤醒

原文:http://www.cnblogs.com/lthxk-yl/p/3535660.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!