public bool WriteFrame(PipeFrame frame)
 {
     if (!this.IsConnected)
     {
         throw new InvalidPipeException("Cannot write Native Stream as pipe is not connected");
     }
     using (MemoryStream memoryStream = new MemoryStream())
     {
         frame.WriteStream((Stream)memoryStream);
         byte[] array = memoryStream.ToArray();
         return(NativePipe.WriteFrame(array, array.Length));
     }
 }
        /// <summary>
        /// Attempts to write a frame
        /// </summary>
        /// <param name="frame"></param>
        /// <returns></returns>
        public bool WriteFrame(PipeFrame frame)
        {
            if (!IsConnected)
            {
                throw new InvalidPipeException("Cannot write Native Stream as pipe is not connected");
            }

            //Create a memory stream so we can write it to the pipe
            using (MemoryStream stream = new MemoryStream())
            {
                //Write the stream and the send it to the pipe
                frame.WriteStream(stream);

                //Get the bytes and send it
                byte[] bytes = stream.ToArray();
                return(NativePipe.WriteFrame(bytes, bytes.Length));
            }
        }