Esempio n. 1
0
 private void Server()
 {
     try
     {
         using (var pipeServer = new NamedPipeServerStream(PipeName, PipeDirection.Out))
         {
             var ss = new StreamString(pipeServer);
             Console.WriteLine($"PortNumberServer Pipe {PipeName} is running.");
             while (true)
             {
                 pipeServer.WaitForConnection();
                 ss.WriteString(_portNumber);
                 pipeServer.WaitForPipeDrain();
                 pipeServer.Disconnect();
             }
         }
     }
     catch (ThreadAbortException)
     {
         Console.WriteLine($"PortNumberServer Pipe {PipeName} stops.");
     }
 }
Esempio n. 2
0
 private void Server()
 {
     try
     {
         var ss = new StreamString(_pipeServerStream);
         Console.WriteLine($"Pipe {_pipeName} is running.");
         // Todo: split Server() method into different steps with events (BeginWaitForConnection ...)
         _pipeServerStream.WaitForConnection();
         while (true)
         {
             Console.WriteLine($"Send server status: \"{Status}\"");
             ss.WriteString(Status.ToString());
             _pipeServerStream.WaitForPipeDrain();
         }
     }
     catch (ThreadAbortException)
     {
         Console.WriteLine($"Pipe {_pipeName} stops.");
     }
     catch (IOException)
     {
         Console.WriteLine($"Pipe {_pipeName} disconnected.");
     }
 }