首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

windows服务中使用System.Timers.Timer计时器,事件不能触发有关问题

2012-07-30 
windows服务中使用System.Timers.Timer计时器,事件不能触发问题如题,在windows服务中使用System.Timers.Ti

windows服务中使用System.Timers.Timer计时器,事件不能触发问题
如题,在windows服务中使用System.Timers.Timer计时器,设置了Elapsed事件,但事件一直不能被触发。代码如下

C# code
private System.Timers.Timer timer;protected override void OnStart(string[] args){      Thread.Sleep(30000);      this.timer = new System.Timers.Timer();      this.timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);      this.timer.Interval = 1000;      this.timer.AutoReset = true;      this.timer.Enabled = true;}void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e){}


[解决办法]
你调试一下不就行了
[解决办法]
你的代码我试过 可以执行到timer的事件的 没有问题 要不你就把代码贴过来看看 

this.timer.AutoReset = true;
不是只执行一次 而是间隔执行 false的话是只执行一次

热点排行