1
我知道這是一個很常見的錯誤,通常具有Windows服務的OnStart方法做的,但我想不通,爲什麼這個ISN」不工作。無法啓動服務:該服務沒有響應控制語句
通過Windows事件查看器錯誤的繼承人堆棧跟蹤:
at System.Diagnostics.EventLog.FindSourceRegistration(System.String, System.String, Boolean, Boolean)
at System.Diagnostics.EventLog.SourceExists(System.String, System.String, Boolean)
at System.Diagnostics.EventLog.SourceExists(System.String)
at ArchivalPurgeService.ArchivalPurge..ctor()
at ArchivalPurgeService.Program.Main()
,這裏是我的程序:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Timers;
namespace ArchivalPurgeService
{
public partial class ArchivalPurge : ServiceBase
{
public ArchivalPurge()
{
try
{
InitializeComponent();
}
catch (Exception ex)
{
}
}
protected override void OnStart(string[] args)
{
try
{
timer2 = new Timer();
timer2.Enabled = true;
timer2.Interval = Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings["RuntimeFrequency"]);
}
catch (Exception ex)
{
}
}
private Queue<Job> QueryDBForJobs()
{
int i = 0;
return new Queue<Job>();
}
protected override void OnStop()
{
}
private void timer2_Elapsed(object sender, ElapsedEventArgs e)
{
QueryDBForJobs();
}
}
}
我想即使一切註釋掉運行它,我會遇到同樣的問題。可能這只是一個安裝問題,也許?我使用的是我創建的安裝程序,幾乎完全基於MSDN如何創建Windows服務。我顯然也在每次代碼更改之後構建/卸載/重新安裝。
可能是一些在'的InitializeComponent()'這是沒有代碼審查。我假設你正在使用一些可視化組件,因爲你的'timer2.Elapsed'事件沒有在代碼中分配,但你看起來似乎是設計器自動生成的代碼。 –
@ErikPhilips好吧,我已經在代碼中,但拿出來調試。但即使刪除了它,我也遇到了同樣的問題。事實上,根本沒有新的代碼,我得到了錯誤。這必須與安裝程序或某事有關,因爲這是我做的唯一不同於以前的Windows服務編寫 –
和initializecomponent現在沒有生成的代碼,除了服務名稱 –