简体   繁体   中英

Running a task in windows service

我正在制作Windows服务,它的任务之一是每1小时要求一个可用的磁盘空间,我知道如何在服务启动时获得可用空间,但是如何每1小时检查一次?

Use a Timer like System.Timers.Timer :

var timer = new System.Timers.Timer();    
timer.Elapsed += new ElapsedEventHandler(TimerElapsed);

timer.Interval = 60 * 60 * 1000; // 1 hour
timer.Enabled = true;

...

private static void TimerElapsed(object source, ElapsedEventArgs e)
{
    // check disk space
} 

Start thread:

while(true){
  getFreeSpace();
  Sleep(3600*1000);
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM