开发者

Most efficient way to run a task on a configurable schedule

开发者 https://www.devze.com 2023-02-01 16:06 出处:网络
I am creating a Windows Service for automated deployment of our software to several different environments.

I am creating a Windows Service for automated deployment of our software to several different environments.

When the service is started it instantiates a custom Deployer object. The Deployer object first reads in a config file containing a list of environments and the times at whic开发者_Python百科h they should be deployed, for example QA-0900,1400 for deploying to QA at 9am and 2pm. Then it starts a Timer with a timeout of 45 seconds and thereafter checks each timeout if the current time matches a time in the list. If it finds a match, it starts the deployment to that environment.

This seems dumb and inefficient to be polling every 45 seconds, but I can think of no better way to do it.

Have any ideas?


Does it have to be a Windows service process? It sounds like something that could be done using the Windows task scheduling system. Especially if you're using Windows Server 2008 the task scheduling is pretty powerful and tasks can be managed programmatically.


Sort the list by the due time, pick the first item, sleep until then.


Check the task scheduler as above ppl have mentioned, though i am not sure of it, plus as they say it is as good as they say in win 2008. for my work, task scheduler was not enough keeping winxp and win2003 server in mind..

In the Win Service, perhaps you create the events that will trigger only at the set time, which you will set when creating the event, so by that time it invokes and your service will then perform the defined task in the event. Other than that Service will work continuously with Thread.Sleep(10000) that be fair enough, you can do a small profiling to see performance \ memory footprint.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号