diff --git a/Lanpartyseating.Desktop/Business/NamedPipeServerHostedService.cs b/Lanpartyseating.Desktop/Business/NamedPipeServerHostedService.cs index 7f66c47..038436c 100644 --- a/Lanpartyseating.Desktop/Business/NamedPipeServerHostedService.cs +++ b/Lanpartyseating.Desktop/Business/NamedPipeServerHostedService.cs @@ -68,12 +68,11 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) while (!stoppingToken.IsCancellationRequested) { - InitializePipeServer(); - - _logger.LogInformation("Waiting for client connection..."); - try { + InitializePipeServer(); + _logger.LogInformation("Waiting for client connection..."); + var waitTask = _server.WaitForConnectionAsync(stoppingToken); var timeoutTask = Task.Delay(TimeSpan.FromSeconds(10), stoppingToken); // Adjust the timeout as needed @@ -139,6 +138,8 @@ private void InitializePipeServer() if (pipeHandle.IsInvalid) { + // Access denied errors have been observed here intermittently. + // Throwing here will cause the server to re-initialize in the run loop above. throw new Win32Exception(Marshal.GetLastWin32Error()); }