Try using it synchronously by importing CreateNamedPipe into your C# application and writing to it as you would a normal file.
Code:
const int PIPE_ACCESS_DUPLEX = 0x00000003;
const int PIPE_ACCESS_INBOUND = 0x00000001;
const int PIPE_ACCESS_OUTBOUND = 0x00000002;
const int FILE_FLAG_FIRST_PIPE_INSTANCE = 0x00080000;
const int PIPE_TYPE_BYTE = 0x00000000;
const int PIPE_TYPE_MESSAGE = 0x00000004;
const int PIPE_READMODE_BYTE = 0x00000000;
const int PIPE_READMODE_MESSAGE = 0x00000002;
const int PIPE_WAIT = 0x00000000;
const int PIPE_NOWAIT = 0x00000001;
const uint GENERIC_READ = 0x80000000;
const uint GENERIC_WRITE = 0x40000000;
const int OPEN_EXISTING = 0x00000003;
[DllImport("kernel32.dll")]
extern static SafeFileHandle CreateNamedPipe(string name, uint openMode, uint pipeMode,
uint maxInstances, uint outBufferSize, uint inBufferSize, uint defaultTimeOut,
IntPtr securityAttributes);
[DllImport("kernel32.dll", SetLastError = true)]
extern static Int32 ConnectNamedPipe(SafeFileHandle namedPipe, IntPtr overlapped);
string pipename = "\\\\.\\pipe\\mypipe"
SafeFileHandle NamedPipe = CreateNamedPipe(pipename, PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, 10, 1000, 1000, 500, IntPtr.Zero);
FileStream pipe = new FileStream(NamedPipe, FileAccess.ReadWrite);
for (byte[] pipeBytes = new byte[255]; pipe.CanRead; pipeBytes = new byte[255];)
{
pipe.Read(pipeBytes, 0, pipeBytes.Length);
pipe.Write(new byte[] { 0xFF, 0xFF }, 0, 2);
str = new StringBuilder();
//print out information
for (int i = 0; i < pipeBytes.Length; i++)
if (pipeBytes[i] != '/0')
str.Append(Convert.ToChar(pipeBytes[i]));
Console.WriteLine("Len: " + str.Length + " -- " + str.ToString());
}