當我嘗試啓動Windows服務後安裝使用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服務器錯誤
這裏沒有足夠的信息來提供有意義的答案。你有沒有檢查過任何日誌或事件查看器?你的服務應該做什麼等等? – Tim
服務是爲了將庫存訂單轉移到亞馬遜mws賬戶而開發的 – Pratik