using System.IO.Pipes; NamedPipeServerStream serverStream = new NamedPipeServerStream("TestPipe"); serverStream.WaitForConnection(); // ... if (serverStream.IsConnected) { serverStream.Disconnect(); }
using System.IO.Pipes; NamedPipeServerStream serverStream = new NamedPipeServerStream("TestPipe"); serverStream.WaitForConnection(); // ... while (serverStream.IsConnected) { // ... } serverStream.Disconnect();In this example, the `Disconnect` method is called after a loop that continues as long as the server stream is connected. This ensures that the connection is terminated after the loop is finished. The package library used for this example is `System.IO.Pipes`.