using System.IO.Pipes; NamedPipeServerStream server = new NamedPipeServerStream("mypipe"); byte[] buffer = new byte[1024]; server.WaitForConnection(); server.BeginRead(buffer, 0, buffer.Length, asyncResult => { int bytesRead = server.EndRead(asyncResult); string message = System.Text.Encoding.Unicode.GetString(buffer, 0, bytesRead); Console.WriteLine(message); }, null);
using System.IO.Pipes; NamedPipeServerStream server = new NamedPipeServerStream("mypipe"); byte[] buffer = new byte[1024]; server.WaitForConnection(); int bytesRead = server.Read(buffer, 0, buffer.Length); server.EndRead(); string message = System.Text.Encoding.Unicode.GetString(buffer, 0, bytesRead); Console.WriteLine(message);In this example, we create a new named pipe server stream and read data synchronously. We use the EndRead() method to signal the end of the read operation. Package/Library: System.IO.Pipes