C# Service: Error 1053: The service did not respond to the start or control request in a timely fashion
-
Hello,
I have a problem with a self programmed windows service for .Net 6 that inherits from BackgroundService:
namespace WooComMesserschmidt
{
internal class Worker : BackgroundService
{
private readonly HttpClient Client = new()
private string BaseAddress = string.Empty;
private readonly IConfiguration Configuration;
private string ConfigFile = string.Empty;
private readonly Dictionary _ConfigPar;
internal static Dictionary ConfigPar = new();
private readonly ILogger _logger;public struct LogInfo { public ILogger? Logger; public string? LogFile; public LogInfo(ILogger? logger, string logfile) { Logger = logger; LogFile = logfile; } } public static LogInfo logInfo; public Worker(ILogger logger, IConfiguration configuration, Dictionary configpar) { Configuration = configuration; \_ConfigPar = configpar; \_logger = logger; Init(); }
...
In the method "Init()" relatively extensive tasks take place (on my PC it takes about 2 seconds). If these are through, it goes on here:
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
if (int.TryParse(ConfigPar[cpQueryInterval], out int QueryInterval) == false)
{
QueryInterval = QueryIntervalStd;
Log.LogInformation(logInfo, $"Abfrageintervall konnte nicht ermittelt werden. Es wird daher der Standardwert von {QueryInterval} Millisekunden verwendet. Prüfen Sie die Angaben in der Parameterdatei.");
}Log.LogInformation(logInfo, $"{Process.GetCurrentProcess().ProcessName} gestartet."); Log.LogInformation(logInfo, $"Worker arbeitet mit Abfrageintervall von {QueryInterval} Millisekunden."); while (stoppingToken.IsCancellationRequested == false) { await ProcessNewOrders(); await UpdateProducts(); Dhl\_Polling(); await Task.Delay(QueryInterval, stoppingToken); } }
...
The service is supposed to fetch orders from an eShop every few minutes, update items and process DHL shipments.
Well, when I start the program manually in the command line (i.e. not as a service), everything works as expected. Now I have registered the program as a service and every time I try to start the service I get the following error:
Error 1053: The service did not respond to th
-
Hello,
I have a problem with a self programmed windows service for .Net 6 that inherits from BackgroundService:
namespace WooComMesserschmidt
{
internal class Worker : BackgroundService
{
private readonly HttpClient Client = new()
private string BaseAddress = string.Empty;
private readonly IConfiguration Configuration;
private string ConfigFile = string.Empty;
private readonly Dictionary _ConfigPar;
internal static Dictionary ConfigPar = new();
private readonly ILogger _logger;public struct LogInfo { public ILogger? Logger; public string? LogFile; public LogInfo(ILogger? logger, string logfile) { Logger = logger; LogFile = logfile; } } public static LogInfo logInfo; public Worker(ILogger logger, IConfiguration configuration, Dictionary configpar) { Configuration = configuration; \_ConfigPar = configpar; \_logger = logger; Init(); }
...
In the method "Init()" relatively extensive tasks take place (on my PC it takes about 2 seconds). If these are through, it goes on here:
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
if (int.TryParse(ConfigPar[cpQueryInterval], out int QueryInterval) == false)
{
QueryInterval = QueryIntervalStd;
Log.LogInformation(logInfo, $"Abfrageintervall konnte nicht ermittelt werden. Es wird daher der Standardwert von {QueryInterval} Millisekunden verwendet. Prüfen Sie die Angaben in der Parameterdatei.");
}Log.LogInformation(logInfo, $"{Process.GetCurrentProcess().ProcessName} gestartet."); Log.LogInformation(logInfo, $"Worker arbeitet mit Abfrageintervall von {QueryInterval} Millisekunden."); while (stoppingToken.IsCancellationRequested == false) { await ProcessNewOrders(); await UpdateProducts(); Dhl\_Polling(); await Task.Delay(QueryInterval, stoppingToken); } }
...
The service is supposed to fetch orders from an eShop every few minutes, update items and process DHL shipments.
Well, when I start the program manually in the command line (i.e. not as a service), everything works as expected. Now I have registered the program as a service and every time I try to start the service I get the following error:
Error 1053: The service did not respond to th
That would suggest that your startup code is taking too long. You mention the
Init
method contains "extensive tasks" - I'd suggest moving some or all of those to the start of theExecuteAsync
method instead.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
That would suggest that your startup code is taking too long. You mention the
Init
method contains "extensive tasks" - I'd suggest moving some or all of those to the start of theExecuteAsync
method instead.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
That would suggest that your startup code is taking too long. You mention the
Init
method contains "extensive tasks" - I'd suggest moving some or all of those to the start of theExecuteAsync
method instead.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
OK, problem solved. The error message had driven me astray and I was looking in the wrong place for the cause of the error. Now I proceeded systematically step by step: at the very beginning, the service crashes without doing anything. The error was due to the "displayname" of the service - this may be maximum 80 characters long, while I used 110 characters. I didn't know that and the error message also said something completely different. Thanks for your help! The weekend is saved! René