[英].Net Core 3.1 Worker as Window Service Error [SC] StartService FAILED 1053:
[英]Error: "[SC] StartService FAILED 1053" while starting a windows service
我在 vs2019 中創建了一個工作服務,但遇到錯誤“[SC] StartService FAILED 1053”。
先說說我是怎么做的。
1、創建工人服務項目
2、發布項目
3、以管理員身份運行cmd.exe
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
然后我遇到了這個錯誤。 如果我直接運行它,exe 運行良好。
為什么我收到此錯誤:
[SC] StartService FAILED 1053:
The service did not respond to the start or control request in a timely fashion.
引發錯誤 1053,因為您創建的應用程序不是真正的 Windows 服務。 擴展 BackgroundService 類來創建服務是不夠的——而是使用ServiceBase 。
本教程概述了要采用的方法。
我目前正在遇到這個問題。 但我敢肯定,在您的情況下,您缺少的是 Nuget 包Microsoft.Extensions.Hosting.WindowsServices
。 然后您必須將HostBuilder
UseWindowsService()
添加到您的HostBuilder
:
public static IHostBuilder CreateHostBuilder(string[] args)
=> Host.CreateDefaultBuilder(args).UseWindowsService().ConfigureServices((hostContext, services)
=> { services.AddHostedService<Worker>(); });
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.