public void Close() { if (_isConnected) { // flush the pipe to allow the client to read the pipe's contents // before disconnecting PipeNative.FlushFileBuffers(_handle); PipeNative.DisconnectNamedPipe(_handle); } // close handle _handle.Dispose(); }
public void DisconnectFromClient() { // check object state if (!_isConnected) { throw new InvalidOperationException("Pipe is not connected"); } // flush internal buffers if (!PipeNative.FlushFileBuffers(_handle)) { throw new PipeIOException(); } // disconnect from the client if (!PipeNative.DisconnectNamedPipe(_handle)) { throw new PipeIOException(); } _isConnected = false; }