看看我的代码:呼叫功能运行在每天的指定时间
Timer myTimer = new Timer { Interval = 1000 };
public void button_Click(object sender, EventArgs e)
{
myTimer.Tick += new EventHandler(OnTick);
myTimer.Start();
}
public void OnTick(object sender, EventArgs ea)
{
myTimer.Stop();
Execute();
}
我想要的功能Execute();
运行在每天指定时间,例如:1h:5min, 1h:25min, 2h10min...
。我使用Timer
,但我只能使该函数每Interval
时间运行。我如何为Timer指定一个绝对时间?
假设您的应用程序将一直运行,您可以编写某种'AlarmClock'类,它维护一个代理列表以及调用它们的时间。在内部,一个计时器会定期启动,检查是否是时候打电话给任何代表了。 –
这可能对您有所帮助http://stackoverflow.com/questions/3243348/how-to-call-a-method-daily-at-specific-time-in-c –
我建议使用Windows计划任务。你还有什么方法可以确保你的应用程序在那个时候运行*? –