我有一个 Windows 服务,当我在本地机器上启动它时,它启动时没有任何问题,但在应用服务器中安装它并尝试启动它后,我收到以下错误:
Windows 无法在本地计算机上启动 MyService 服务
<块引用>错误 1053:服务没有响应启动或控制 及时请求。
我尝试在编译时将调试模式更改为发布 dll。没用
代码:
public partial class Service1 : ServiceBase
{
Timer timer = new Timer();
public Service1()
{
InitializeComponent();
}
public void onDebug()
{
OnStart(null);
}
protected override void OnStart(string[] args)
{
WriteToFile("Service is started at " + DateTime.Now);
timer.Elapsed += new ElapsedEventHandler(OnElapsedTime);
timer.Interval = Convert.ToInt32(ConfigurationManager.AppSettings["RuntimeFrequency"]); //number in milisecinds
timer.Enabled = true;
}
protected override void OnStop()
{
WriteToFile("Service stopped at " + DateTime.Now);
}
主要方法:
#if DEBUG
// While debugging this section is used.
Service1 myService = new Service1();
myService.onDebug();
System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
#else
// In Release this section is used. This is the "normal" way.
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new Service1()
};
ServiceBase.Run(ServicesToRun);
#endif
}