使用窗口服务的C#我想根据我的配置标签运行的服务,其实我会在这里设定值的app.config中的三个标签下面提到逻辑
<add key ="FIREHOST_TIME" value ="5" ></add>
<add key ="SETDAYS" value ="3" ></add>
<add key ="RUN_NOW" value ="1" ></add> <!-- 0=no, 1=yes-->
如果假设RUN_NOW值是1,
当服务启动时,它现在要做的工作,并为下一个实例它应该运行基于由SETDAYS标签。
如果假设RUN_NOW值为0,
当服务启动时,它不应该这样做,应该等待工作SETDAYS来,然后下一个实例应该为每一套天标签运行。
这里下面我已经粘贴代码:
protected override void OnStart(string[] args)
{
DateTime tenAM = DateTime.Today.AddHours(FIREHOST_TIME);
if (DateTime.Now > tenAM)
tenAM = tenAM.AddDays(SETDAYS);
// calculate milliseconds until the next 10:00 AM.
int timeToFirstExecution = (int)tenAM.Subtract(DateTime.Now).TotalMilliseconds;
// calculate the number of milliseconds in 24 hours.
int timeBetweenCalls = (int)new TimeSpan(24, 0, 0).TotalMilliseconds;
TimerCallback methodToExecute = kickstart;
// start the timer. The timer will execute "ProcessFile" when the number of seconds between now and
// the next 10:00 AM elapse. After that, it will execute every 24 hours.
System.Threading.Timer timer = new System.Threading.Timer(methodToExecute, null, timeToFirstExecution, timeBetweenCalls);
}
所以现在我不得不使用标签帮助RUN_NOW和实现逻辑,请指教如何执行。
的文档你的问题是过高的水平,人们可能会发现很难在这里你需要有更好的问题回答合乎逻辑的问题。 – 2012-07-16 11:44:34