【发布时间】:2014-06-30 18:23:50
【问题描述】:
我在这里有点新。我有一个窗口服务,其中我有一个计时器,它在 1 分钟间隔后执行一个函数..我想在计时器启动之前第一次执行函数,然后在每个计时器间隔之后执行......
这是我的代码:
public partial class ASMSFetchService : ServiceBase
{
System.Timers.Timer updateAutoSMSTimer;
public ASMSFetchService()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
updateAutoSMSTimer = new System.Timers.Timer(1 * 60 * 1000);
updateAutoSMSTimer.Elapsed += new System.Timers.ElapsedEventHandler(Slots);
updateAutoSMSTimer.Enabled = true;
updateAutoSMSTimer.AutoReset = true;
updateAutoSMSTimer.Start();
}
private void Slots(object sender, ElapsedEventArgs e)
{method1();}
private void method1()
{ //SomeOpeartion }
}
该函数在 1 个定时器间隔完成时执行...我想在定时器启动之前调用 method1(),然后在每个定时器间隔之后调用 ....
我尝试将方法放在 Start() 和 constructor() 中..但它不起作用......我不确定..但有可能吗???
任何建议都会有帮助
【问题讨论】: