@@ -33,6 +33,7 @@ public class NamedPipeServer : IDisposable
3333 /// </summary>
3434 public async Task StartAsync ( CancellationToken cancellationToken )
3535 {
36+ Console . Error . WriteLine ( $ "[DEBUG] NamedPipeServer.StartAsync called, MaxConcurrentConnections={ MaxConcurrentConnections } ") ;
3637 using var combinedCts = CancellationTokenSource . CreateLinkedTokenSource (
3738 cancellationToken , _internalCancellation . Token ) ;
3839
@@ -41,20 +42,25 @@ public async Task StartAsync(CancellationToken cancellationToken)
4142 // Start multiple server instances
4243 for ( int i = 0 ; i < MaxConcurrentConnections ; i ++ )
4344 {
45+ Console . Error . WriteLine ( $ "[DEBUG] Starting server instance { i + 1 } /{ MaxConcurrentConnections } ") ;
4446 var task = RunServerInstanceAsync ( combinedCts . Token ) ;
4547 _serverTasks . Add ( task ) ;
4648 }
4749
50+ Console . Error . WriteLine ( "[DEBUG] All server instances started, waiting for completion..." ) ;
4851 // Wait for all server instances to complete
4952 await Task . WhenAll ( _serverTasks ) ;
53+ Console . Error . WriteLine ( "[DEBUG] All server instances completed" ) ;
5054 }
5155 catch ( OperationCanceledException )
5256 {
57+ Console . Error . WriteLine ( "[DEBUG] StartAsync cancelled" ) ;
5358 // Cancellation is normal termination
5459 }
5560 catch ( Exception ex )
5661 {
57- Console . Error . WriteLine ( $ "Named Pipe Server error: { ex . Message } ") ;
62+ Console . Error . WriteLine ( $ "[ERROR] Named Pipe Server error: { ex . GetType ( ) . Name } : { ex . Message } ") ;
63+ Console . Error . WriteLine ( $ "[ERROR] Stack trace: { ex . StackTrace } ") ;
5864 }
5965 }
6066
@@ -63,25 +69,31 @@ public async Task StartAsync(CancellationToken cancellationToken)
6369 /// </summary>
6470 private async Task RunServerInstanceAsync ( CancellationToken cancellationToken )
6571 {
72+ Console . Error . WriteLine ( $ "[DEBUG] RunServerInstanceAsync started on thread { Environment . CurrentManagedThreadId } ") ;
6673 while ( ! cancellationToken . IsCancellationRequested )
6774 {
6875 try
6976 {
77+ Console . Error . WriteLine ( "[DEBUG] Creating Named Pipe server..." ) ;
7078 using var pipeServer = CreateNamedPipeServer ( ) ;
79+ Console . Error . WriteLine ( $ "[DEBUG] Named Pipe server created, waiting for connection...") ;
7180
7281 // Wait for client connection
7382 await pipeServer . WaitForConnectionAsync ( cancellationToken ) ;
83+ Console . Error . WriteLine ( "[DEBUG] Client connected to Named Pipe" ) ;
7484
7585 // Handle communication with connected client
7686 await HandleClientAsync ( pipeServer , cancellationToken ) ;
7787 }
7888 catch ( OperationCanceledException )
7989 {
90+ Console . Error . WriteLine ( "[DEBUG] Named Pipe server cancelled" ) ;
8091 break ;
8192 }
8293 catch ( Exception ex )
8394 {
84- Console . Error . WriteLine ( $ "Named Pipe Server instance error: { ex . Message } ") ;
95+ Console . Error . WriteLine ( $ "[ERROR] Named Pipe Server instance error: { ex . GetType ( ) . Name } : { ex . Message } ") ;
96+ Console . Error . WriteLine ( $ "[ERROR] Stack trace: { ex . StackTrace } ") ;
8597
8698 // Wait a moment before retrying on error
8799 try
@@ -94,19 +106,31 @@ private async Task RunServerInstanceAsync(CancellationToken cancellationToken)
94106 }
95107 }
96108 }
109+ Console . Error . WriteLine ( "[DEBUG] RunServerInstanceAsync exiting" ) ;
97110 }
98111
99112 /// <summary>
100113 /// Creates a Named Pipe server
101114 /// </summary>
102115 private static NamedPipeServerStream CreateNamedPipeServer ( )
103116 {
104- return new NamedPipeServerStream (
105- PipeName ,
106- PipeDirection . InOut ,
107- NamedPipeServerStream . MaxAllowedServerInstances ,
108- PipeTransmissionMode . Byte ,
109- PipeOptions . Asynchronous ) ;
117+ Console . Error . WriteLine ( $ "[DEBUG] CreateNamedPipeServer: PipeName={ PipeName } ") ;
118+ try
119+ {
120+ var server = new NamedPipeServerStream (
121+ PipeName ,
122+ PipeDirection . InOut ,
123+ NamedPipeServerStream . MaxAllowedServerInstances ,
124+ PipeTransmissionMode . Byte ,
125+ PipeOptions . Asynchronous ) ;
126+ Console . Error . WriteLine ( $ "[DEBUG] NamedPipeServerStream created successfully") ;
127+ return server ;
128+ }
129+ catch ( Exception ex )
130+ {
131+ Console . Error . WriteLine ( $ "[ERROR] Failed to create NamedPipeServerStream: { ex . GetType ( ) . Name } : { ex . Message } ") ;
132+ throw ;
133+ }
110134 }
111135
112136 /// <summary>
0 commit comments