Windows服务项目在启动服务时失败,出现1053错误

时间:2019-05-08 08:26:50

标签: c#

我想用Visual Studio创建Windows服务应用程序。启动服务时出现此错误:

  

错误1053,服务未响应启动或控制请求   及时

所以我删除了代码,仍然遇到此错误。也许我错过了一些设置,所以这是我要复制的项目:

  • 首先使用Visual Studio创建Windows Service App(C#)

  • 将体系结构设置为x86。

  • 将输出路径设置为另一个目录,我的目录是 C:\ Program Files(x86)\ Kofax \ CaptureSS \ ServLib \ Bin

  • 将所需的dll添加到项目中,例如 PDFSharp

  • 将Program.cs更新为调试模式( RuntimeService 是我的服务文件)

    private static void Main()
    {
    #if DEBUG
        new RuntimeService().RunDebugMode();
        Thread.Sleep(TimeSpan.FromDays(1));
    #else
        ServiceBase.Run(new RuntimeService());
    #endif
    }
    
  • 我的 RuntimeService.cs 包含以下代码

    public RuntimeService()
    {
        InitializeComponent();
    }
    
    public void RunDebugMode()
    {
        OnStart(null);
    }
    
    protected override void OnStart(string[] args)
    {
       // nothing in here
    }
    
    protected override void OnStop()
    {
    }
    
  • 将安装程序文件添加到服务文件。

  • 将帐户设置为本地服务

  • 将起始类型设置为 automatic

  • 构建项目一次,我的项目文件已部署到 C:\ Program Files(x86)\ Kofax \ CaptureSS \ ServLib \ Bin

  • 在该目录中创建一个.bat文件并使用此内容

    “ C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ installutil.exe”“ C:\ Program Files(x86)\ Kofax \ CaptureSS \ ServLib \ Bin \ DemoService.exe” 暂停

  • 重新启动计算机(我这样做了...)

  • 转到Windows服务面板并搜索您的服务。排雷设置为自动。启动服务。

    启动它时,出现上述错误。那我想念什么吗?

如果相关,我可以在Windows 10上使用虚拟机。

1 个答案:

答案 0 :(得分:0)

我通过从调试模式切换到发布模式解决了该问题。答案来自这里

https://stackoverflow.com/a/4305082/9945420