Windows服务自动停止 [英] Windows service stops automatically

查看:304
本文介绍了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
}

这篇关于Windows服务自动停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆