【发布时间】:2015-07-06 08:51:10
【问题描述】:
我有一个使用计时器的 Windows 服务。计时器每隔几秒钟工作一次,并检查数据库中的一些更改,然后如果有任何更改,Windows 服务会执行操作。
我做了所有事情,在我的机器上进行了繁重的测试,在我的机器上,windows 服务运行良好。
当我在服务器上部署时,Windows 服务会在我 start Windows 服务时检查数据库更改,但它不会继续检查数据库中的任何更改。我不知道问题所在,我已经连续三天在这里呆了,我检查了所有内容。
在我的机器上我使用框架 32 进行部署,在服务器上我也使用框架 32 进行部署。
我也尝试使用framework 64在服务器上部署,但还是同样的问题。
我为任何失败做了一个日志,根本没有错误日志。
您能告诉我问题可能出在哪里吗?
我用这样的计时器运行 Windows 服务:
private System.Timers.Timer timer;
public ServiceStatus()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
try
{
this.timer = new System.Timers.Timer(30000); // 30000 milliseconds = 30 seconds
this.timer.AutoReset = true;
this.timer.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_Elapsed);
this.timer.Start();
}
catch (Exception ee)
{
this.EventLog.WriteEntry("ERROR ERROR ERROR="+ee.Message);
}
}
protected override void OnStop()
{
this.timer.Stop();
this.timer = null;
}
private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
new StatusHandler().check();
}
已经三天了,我无法解决,不胜感激。
【问题讨论】:
-
在您发布的代码中,您没有处理对
StatusHandler().check();的调用中的任何错误。因此,如果抛出异常,它将退出服务并显示您所描述的行为。当然,除非您的check方法确实有错误处理,否则可能会显示代码? -
@Belogix 好的,我会上传更多代码,请稍等
-
@Belogix 我刚刚添加了 try and catch 并再次部署,如果日志中发生任何错误,我会通知您
-
@Belogix 哦哦哦我开始在日志中出现错误
Object reference not set to an instance of an object. -
那就是问题所在! :-) 希望现在您可以找到错误并修复它。