Click here to Skip to main content
15,888,461 members
Home / Discussions / C#
   

C#

 
GeneralRe: Async - await Pin
Richard Deeming20-Sep-22 5:01
mveRichard Deeming20-Sep-22 5:01 
AnswerRe: Async - await PinPopular
Richard Deeming20-Sep-22 5:06
mveRichard Deeming20-Sep-22 5:06 
GeneralRe: Async - await Pin
MarkTJohnson20-Sep-22 5:47
professionalMarkTJohnson20-Sep-22 5:47 
GeneralRe: Async - await Pin
dataminers21-Sep-22 0:04
dataminers21-Sep-22 0:04 
GeneralRe: Async - await Pin
Richard Deeming21-Sep-22 2:07
mveRichard Deeming21-Sep-22 2:07 
GeneralRe: Async - await Pin
dataminers21-Sep-22 5:33
dataminers21-Sep-22 5:33 
QuestionHow to make a license key system with Realtime DB? Pin
Moses Man19-Sep-22 0:11
Moses Man19-Sep-22 0:11 
AnswerRe: How to make a license key system with Realtime DB? Pin
OriginalGriff19-Sep-22 2:21
mveOriginalGriff19-Sep-22 2:21 
QuestionHow to create a many-to-many relationship between users in a table? Pin
Alex Wright 202216-Sep-22 6:16
Alex Wright 202216-Sep-22 6:16 
AnswerRe: How to create a many-to-many relationship between users in a table? Pin
Gerry Schmitz16-Sep-22 6:30
mveGerry Schmitz16-Sep-22 6:30 
GeneralRe: How to create a many-to-many relationship between users in a table? Pin
Alex Wright 202216-Sep-22 6:33
Alex Wright 202216-Sep-22 6:33 
GeneralRe: How to create a many-to-many relationship between users in a table? Pin
Gerry Schmitz16-Sep-22 6:42
mveGerry Schmitz16-Sep-22 6:42 
GeneralRe: How to create a many-to-many relationship between users in a table? Pin
Alex Wright 202216-Sep-22 6:55
Alex Wright 202216-Sep-22 6:55 
GeneralRe: How to create a many-to-many relationship between users in a table? Pin
Eddy Vluggen16-Sep-22 23:59
professionalEddy Vluggen16-Sep-22 23:59 
SuggestionRe: How to create a many-to-many relationship between users in a table? Pin
Richard Deeming19-Sep-22 21:16
mveRichard Deeming19-Sep-22 21:16 
QuestionProgram instalator in C#, Visual Studio Pin
Ismael_199912-Sep-22 5:36
Ismael_199912-Sep-22 5:36 
AnswerRe: Program instalator in C#, Visual Studio Pin
Gerry Schmitz12-Sep-22 6:21
mveGerry Schmitz12-Sep-22 6:21 
AnswerRe: Program instalator in C#, Visual Studio Pin
OG MAYOR MRL25-Sep-22 2:48
OG MAYOR MRL25-Sep-22 2:48 
Questionreading memory stream in byte chunks Pin
mjeeves10-Sep-22 8:41
mjeeves10-Sep-22 8:41 
GeneralRe: reading memory stream in byte chunks Pin
harold aptroot10-Sep-22 9:49
harold aptroot10-Sep-22 9:49 
GeneralRe: reading memory stream in byte chunks Pin
mjeeves10-Sep-22 10:04
mjeeves10-Sep-22 10:04 
GeneralRe: reading memory stream in byte chunks Pin
harold aptroot10-Sep-22 10:15
harold aptroot10-Sep-22 10:15 
QuestionC# Service: Error 1053: The service did not respond to the start or control request in a timely fashion Pin
temuco8-Sep-22 20:41
professionaltemuco8-Sep-22 20:41 
Hello,

I have a problem with a self programmed windows service for .Net 6 that inherits from BackgroundService:

C#
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<string, dynamic?>	_ConfigPar;
		internal static	 Dictionary<string, string>		ConfigPar		= new();
		private readonly ILogger<Worker>				_logger;

		public struct LogInfo
		{
			public ILogger<Worker>? Logger;
			public string?			LogFile;

			public LogInfo(ILogger<Worker>? logger, string logfile)
			{
				Logger	= logger;
				LogFile	= logfile;
			}
		}

		public static LogInfo logInfo;

		public Worker(ILogger<Worker> logger, IConfiguration configuration, Dictionary<string, dynamic?> 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:


C#
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 the start or control request in a timely fashion
We started everything in Main:

C#
private static async Task<int> Main(string[] args)
		{
			try
			{
				IHost host = Host.CreateDefaultBuilder(args)
					.UseWindowsService(options =>
					{
						options.ServiceName = ServiceName;
					})
					.ConfigureServices(services =>
					{
						services.AddSingleton<Dictionary<string, dynamic?>> (_ConfigPar);

						services.AddHostedService<Worker>();
					})
					.Build();

				await host.RunAsync();

				Log.LogInformation((LogInfo)_ConfigPar[cpLogInfo], $"{Process.GetCurrentProcess().ProcessName} beendet.");

				if (Debugger.IsAttached == true)
				{
					Console.ReadLine();
				}
			}
			catch (Exception ex)
			{
				Console.WriteLine($"{ex}{Environment.NewLine}{Environment.NewLine}");
...

How do I proceed to avoid this error?

Many thanks

René

AnswerRe: C# Service: Error 1053: The service did not respond to the start or control request in a timely fashion Pin
Richard Deeming8-Sep-22 21:49
mveRichard Deeming8-Sep-22 21:49 
GeneralRe: C# Service: Error 1053: The service did not respond to the start or control request in a timely fashion Pin
temuco8-Sep-22 22:34
professionaltemuco8-Sep-22 22:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.