using System.IO.Pipes; using System.Text; NamedPipeServerStream pipeServer = new NamedPipeServerStream("mypipe"); byte[] buffer = Encoding.UTF8.GetBytes("Hello world"); pipeServer.WaitForConnection(); pipeServer.BeginWrite(buffer, 0, buffer.Length, (ar) => { pipeServer.EndWrite(ar); pipeServer.Dispose(); }, null);
using System.IO.Pipes; using System.Text; NamedPipeServerStream pipeServer = new NamedPipeServerStream("mypipe"); pipeServer.WaitForConnection(); while (pipeServer.IsConnected) { byte[] buffer = Encoding.UTF8.GetBytes("Hello world"); pipeServer.BeginWrite(buffer, 0, buffer.Length, null, null); }This code initializes a NamedPipeServerStream with the name "mypipe". It then waits for a connection from a client and enters into an infinite loop that continuously writes "Hello world" to the pipe using BeginWrite. This is a simple example of how to continuously send data between two processes. The NamedPipeServerStream class is part of the System.IO.Pipes package library in C#.