加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

.net – Windows无法在Win Server 2008 R2 SP1上启动服务(错误10

发布时间:2020-12-14 01:41:18 所属栏目:Windows 来源:网络整理
导读:这个问题似乎得到广泛的讨论,但是在我的具体情况下找到解决方案有问题. 我的服务设置为在本地系统帐户下运行.在安装了Windows 7 SP1(64位)的第一台机器上,一切正常工作.但是,在我尝试在Windows Server 2008 R2 SP1(64位)的第二台机器上启动服务之后,甚至没有
这个问题似乎得到广泛的讨论,但是在我的具体情况下找到解决方案有问题.

我的服务设置为在本地系统帐户下运行.在安装了Windows 7 SP1(64位)的第一台机器上,一切正常工作.但是,在我尝试在Windows Server 2008 R2 SP1(64位)的第二台机器上启动服务之后,甚至没有第二次通过,我面临着这个令人讨厌的错误:

Windows could not start the ProService service on Local Computer
Error 1053: The service did not respond to the start or control request in a timely fashion

系统日志显示2个条目:

The ProService service failed to start due to the following error: 
The service did not respond to the start or control request in a timely fashion.

和:

A timeout was reached (30000 milliseconds) while waiting for the ProService service to connect.

实现方式如下:

Program.cs中:

static void Main()
{
    AppDomain.CurrentDomain.UnhandledException += CurrentDomainUnhandledException;
    ServiceBase.Run(new ServiceBase[] { new ProService() });
}

static void CurrentDomainUnhandledException(object sender,UnhandledExceptionEventArgs e)
{
    if (e != null && e.ExceptionObject != null)
    {
        Logger.Record(e.ExceptionObject);
    }            
}

ProService.cs:

public ProService()
{
    InitializeComponent();
}

protected override void OnStart(string[] args)
{
    try
    {
        RequestAdditionalTime(10000);
        FireStarter.Instance.Execute();
    }
    catch (Exception e)
    {
        Logger.Record(e);
        throw;
    }            
}

OnStart方法只是启动一个新的线程,所以几乎没有时间加载来执行.我使用RequestAdditionalTime语句,以防万一 – 拒绝这个问题作为我的问题的根源.另外,正如你所看到的那样,我正在处理所有的异常,但在启动期间(btw:logging正在第一个win7机器上工作)也没有异常写入我的自定义服务事件日志.如何调查发生了什么?

我已经弄清楚发生了几个步骤:

>我已经编写了控制台应用程序 – 包装器,基本上是从OnStart方法中完成的.
>我已经执行了控制台应用程序 – 应用程序正常启动.
>我将服务配置文件的内容复制到控制台应用程序配置文件.
>我再次执行了控制台应用程序 – 应用程序静默地立即中止(令人惊讶的类似于我们的服务行为,有些是错误的).
>我比较了2个配置 – 从服务和原始的控制台应用程序.结果我发现了一些差异.其中有这样一个条目 – 问题的根源(删除后,一切正常):

<startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>

所以基本上我有过时的配置文件.以前的服务是在.NET 4.5下编译的,然后将框架改为4.0,并将文件部署到服务器,但是保留了以前的配置文件(我已经改变了目标框架,因为我的开发机器具有.NET 4.5,而服务器不).我不会想到所示的行将隐藏所有问题,没有任何合理的信息,这可以帮助跟踪混乱.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读