Windows服务自动停止
我做了一个窗口服务,并让它自动在本地系统账户的工作,在服务启动时,它触发这个消息对我来说,然后停止
I made a Window service and let it work automatically and under localsystem account, when the service starts it fires this message for me and then stops
在本地计算机的[服务名称]服务启动,然后停止。如果他们不被其他服务或程序使用一些服务自动停止。
The [service name] service on local computer started and then stopped. Some Services stop automatically if they are not in use by another services or programs.
有什么问题,有什么解决办法?
What's the problem and what's the solution?
无论你是不会启动任何线程在OnStart方法做的工作,或者有你的OnStart方法中引发异常。
Either you are not starting any threads on the OnStart method to do work, or there is an exception raised within your OnStart method.
如果抛出一个异常,它会出现在Windows事件日志。 Windows事件日志是一个良好的开端,在任何情况下。
If an exception is thrown, it will appear in the Windows Event log. The Windows Event log is a good place to start in any case.
通常是OnStart方法是这样的:
Generally an OnStart method looks like this:
Thread _thread;
protected override void OnStart(string[] args)
{
// Comment in to debug
// Debugger.Break()
// Do initial setup and initialization
Setup();
// Kick off a thread to do work
_thread = new Thread(new MyClass().MyMethod)
_thread.Start();
// Exit this method to indicate the service has started
}