public static void Flush(PipeHandle handle)
 {
     handle.State = InterProcessConnectionState.Flushing;
     NamedPipeNative.FlushFileBuffers(handle.Handle);
     handle.State = InterProcessConnectionState.FlushedData;
 }
 public static void Disconnect(PipeHandle handle)
 {
     handle.State = InterProcessConnectionState.Disconnecting;
     NamedPipeNative.DisconnectNamedPipe(handle.Handle);
     handle.State = InterProcessConnectionState.Disconnected;
 }
        public static uint NumberPipeInstances(PipeHandle handle)
        {
            uint curInstances = 0;

            if (NamedPipeNative.GetNamedPipeHandleState(handle.Handle, IntPtr.Zero, ref curInstances, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero))
            {
                return(curInstances);
            }
            else
            {
                throw new Exception("Error getting the pipe state. Internal error: " + NamedPipeNative.GetLastError().ToString());
            }
        }