简体   繁体   English

错误:启动 Windows 服务时出现“[SC] StartService FAILED 1053”

[英]Error: "[SC] StartService FAILED 1053" while starting a windows service

I created a worker service in vs2019, but met error "[SC] StartService FAILED 1053".我在 vs2019 中创建了一个工作服务,但遇到错误“[SC] StartService FAILED 1053”。

在此处输入图片说明

Let me first talk about how I did it.先说说我是怎么做的。

1, Create a worker service project 1、创建工人服务项目

在此处输入图片说明

在此处输入图片说明

2, Publish the project 2、发布项目

在此处输入图片说明

3, Run cmd.exe as Administrator 3、以管理员身份运行cmd.exe

在此处输入图片说明

4, Create windows service "testworker" and start it 4、创建windows服务“testworker”并启动

sc Create testworker BinPath="c:\Users\zxi.BS\source\repos\WorkerService1\WorkerService1\bin\Release\net5.0\publish\WorkerService1.exe"
sc start testworker

Then i met this error.然后我遇到了这个错误。 The exe runs well if i run it directly.如果我直接运行它,exe 运行良好。 在此处输入图片说明

Why did i get this error:为什么我收到此错误:

[SC] StartService FAILED 1053:

The service did not respond to the start or control request in a timely fashion.

Error 1053 is raised because the application you have created is not a true Windows Service.引发错误 1053,因为您创建的应用程序不是真正的 Windows 服务。 It's not sufficient to extend the BackgroundService class to create a service — work with ServiceBase instead.扩展 BackgroundService 类来创建服务是不够的——而是使用ServiceBase

This tutorial outlines the approach to take. 本教程概述了要采用的方法。

I'm currently running into this issue.我目前正在遇到这个问题。 But I'm sure in your case, what you are missing is the Nuget package Microsoft.Extensions.Hosting.WindowsServices .但我敢肯定,在您的情况下,您缺少的是 Nuget 包Microsoft.Extensions.Hosting.WindowsServices You must then add UseWindowsService() to your HostBuilder :然后您必须将HostBuilder UseWindowsService()添加到您的HostBuilder

public static IHostBuilder CreateHostBuilder(string[] args)
            => Host.CreateDefaultBuilder(args).UseWindowsService().ConfigureServices((hostContext, services)
                => { services.AddHostedService<Worker>(); });

Source: https://github.com/dotnet/extensions/issues/2496来源: https : //github.com/dotnet/extensions/issues/2496

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM