到目前为止,我已经实施了这个例子但没有运气,
public class WCFService : System.Timers.Timer, IWCFService
{
public WCFService()
{
base.Interval = 10000;
this.Enabled = true;
this.Elapsed += new
System.Timers.ElapsedEventHandler(WCFService_Elapsed);
}
void WCFService_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
//Do Checking
}
应该在10000ms之后调用 WCFService_Elapsed
,但在调试期间它现在正在工作。有什么想法吗?
我正在尝试自我检查一些变量并在某些情况下发送电子邮件。
答案 0 :(得分:1)
在启用计时器之前指定您已用完的事件会有什么不同吗?如果我有代表,我会将此作为评论添加。
答案 1 :(得分:0)
我将代码更改为:
public class WCFService : IWCFService
{
public WCFService()
{
System.Timers.Timer timer = new System.Timers.Timer();
timer.Elapsed += new System.Timers.ElapsedEventHandler(WCFService_Elapsed);
timer.Interval = 1000;
timer.Enabled = true;
timer.Start();
}
void WCFService_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
//Do Checking
}
这确实有效,但我必须至少调用一次来自服务的方法来启动计时器。