Click here to Skip to main content
15,885,855 members
Home / Discussions / C#
   

C#

 
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[Solved] Re: C# Service: Error 1053: The service did not respond to the start or control request in a timely fashion Pin
temuco9-Sep-22 1:38
professionaltemuco9-Sep-22 1:38 
QuestionC# Battleship gameboard & random assignment Pin
Otto_W5-Sep-22 17:50
Otto_W5-Sep-22 17:50 
AnswerRe: C# Battleship gameboard & random assignment Pin
OriginalGriff5-Sep-22 19:11
mveOriginalGriff5-Sep-22 19:11 
GeneralRe: C# Battleship gameboard & random assignment Pin
Otto_W6-Sep-22 15:51
Otto_W6-Sep-22 15:51 
GeneralRe: C# Battleship gameboard & random assignment Pin
OriginalGriff6-Sep-22 19:19
mveOriginalGriff6-Sep-22 19:19 
GeneralRe: C# Battleship gameboard & random assignment Pin
Otto_W16-Sep-22 21:54
Otto_W16-Sep-22 21:54 
GeneralRe: C# Battleship gameboard & random assignment Pin
OriginalGriff16-Sep-22 22:13
mveOriginalGriff16-Sep-22 22:13 
GeneralRe: C# Battleship gameboard & random assignment Pin
Otto_W24-Sep-22 1:09
Otto_W24-Sep-22 1:09 
GeneralRe: C# Battleship gameboard & random assignment Pin
OriginalGriff24-Sep-22 1:34
mveOriginalGriff24-Sep-22 1:34 
GeneralRe: C# Battleship gameboard & random assignment Pin
Otto_W24-Sep-22 2:45
Otto_W24-Sep-22 2:45 
GeneralRe: C# Battleship gameboard & random assignment Pin
OriginalGriff24-Sep-22 3:16
mveOriginalGriff24-Sep-22 3:16 
GeneralRe: C# Battleship gameboard & random assignment Pin
Otto_W25-Sep-22 21:20
Otto_W25-Sep-22 21:20 
GeneralRe: C# Battleship gameboard & random assignment Pin
OriginalGriff25-Sep-22 22:01
mveOriginalGriff25-Sep-22 22:01 
GeneralRe: C# Battleship gameboard & random assignment Pin
Otto_W29-Sep-22 16:23
Otto_W29-Sep-22 16:23 
GeneralRe: C# Battleship gameboard & random assignment Pin
OriginalGriff29-Sep-22 19:10
mveOriginalGriff29-Sep-22 19:10 

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.