【发布时间】:2015-05-21 14:55:52
【问题描述】:
当我在使用 nssm 安装后尝试启动 Windows 服务时,会显示以下错误
添加代码
#region Private Members
private Timer timer1 = null;
#endregion
#region Constructor
public Service1()
{
InitializeComponent();
}
#endregion
#region Methods
/// <summary>
/// This function run on Windows service Start event
/// </summary>
/// <param name="args">args</param>
protected override void OnStart(string[] args)
{
try
{
timer1 = new Timer();
this.timer1.Interval = 60000; //1 Minute=60000, 2 Minute=120000,5 Minute=300000
this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(this.timer1_Tick);
timer1.Enabled = true;
Library.WriteErrorLog(" ============================ ");
Library.WriteErrorLog(" Windows Service Started. ");
}
catch (Exception ex)
{
Library.WriteErrorLog(" WCF Service Error Given In OnStart() Is : " + ex.Message);
}
}
/// <summary>
/// OnStop event will hit when Windows service Stop
/// </summary>
protected override void OnStop()
{
timer1.Enabled = false;
Library.WriteErrorLog(" Windows Service Stopped. ");
}
/// <summary>
/// timer1_Tick event will call in every Timer Interval as well Window Service Started
/// </summary>
/// <param name="state"></param>
private void timer1_Tick(object sender, ElapsedEventArgs e)
{
Library.WriteErrorLog("---------------------------------");
Library.WriteErrorLog(" Windows Service Timer Ticked and Doing His Job Succcessfully. ");
Library.WriteErrorLog(" Windows Service Timer Call After 1 Minute. ");
Library.WriteErrorLog(" WCF Service Call Started. ");
TimerCalled();
}
/// <summary>
/// This function will called in 'x' time interval. common function will call from OnElapsedTime event
/// </summary>
/// <param name="b"></param>
private void TimerCalled()
{
try
{
Library.WriteErrorLog(" WCF Service Call By Using Windows Service Timer. ");
DbChecker obj = new DbChecker();
Boolean bl = obj.checkRecord();
Library.WriteErrorLog(" Windows Service Timer Call End. ");
Library.WriteErrorLog("---------------------------------");
}
catch (Exception ex)
{
Library.WriteErrorLog(" WCF Service Error Given In TimerCalled() Is : " + ex.Message);
}
}
#endregion
当我当时调试我的解决方案时,我没有收到任何错误或警告...服务运行完美,但我认为可能是 Windows 服务器错误
【问题讨论】:
-
这里没有足够的信息来提供有意义的答案。您是否检查过任何日志或事件查看器?您的服务应该做什么等?
-
服务正在开发用于将库存订单转移到亚马逊 mws 帐户