this.m_Pipe = new NamedPipeClientStream(".", _PipeName, PipeDirection.InOut, PipeOptions.Asynchronous);
lastPipeStream = new NamedPipeServerStream(_PipeName, PipeDirection.InOut, maxNumberOfServerInstances, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
这两个怎么没有你所说的那些

解决方案 »

  1.   


    嗯?请问你说的是什么?我自己倒入了一个NamedPipeNative的库,这个是在vc中封装好了的。using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Runtime.InteropServices;
    namespace NamedPipeLib
    {    public static class NamedPipeNative
        {
            public const uint PIPE_ACCESS_DUPLEX = 0x00000003;        public const uint PIPE_READMODE_MESSAGE = 0x00000002;        public const uint PIPE_TYPE_MESSAGE = 0x00000004;        public const uint PIPE_WAIT = 0x00000000;        public const uint PIPE_UNLIMITED_INSTANCES = 255;        public const int INVALID_HANDLE_VALUE = -1;        public const ulong ERROR_PIPE_CONNECTED = 535;        public const uint GENERIC_WRITE = (0x40000000);        public const uint GENERIC_READ = (0x80000000);        public const uint OPEN_EXISTING = 3;        public const ulong ERROR_PIPE_BUSY = 231;        [DllImport("kernel32.dll", SetLastError = true)]
            public static extern IntPtr CreateFile(
                String lpFileName,   // file name
                uint dwDesiredAccess,   // access mode
                uint dwShareMode, // share mode
                SecurityAttributes attr, // SD
                uint dwCreationDisposition, // how to create
                uint dwFlagsAndAttributes, // file attributes
                uint hTemplateFile);        [DllImport("kernel32.dll", SetLastError = true)]
            public static extern IntPtr CreateNamedPipe(
                String lpName, // pipe name
                uint dwOpenMode, // pipe open mode
                uint dwPipeMode, // pipe-specific modes
                uint nMaxInstances, // maximum number of instances
                uint nOutBufferSize, // output buffer size
                uint nInBufferSize, // input buffer size
                uint nDefaultTimeOut, // time-out interval
                IntPtr pipeSecurityDescriptor // SD
                );
            [DllImport("kernel32.dll", SetLastError = true)]
            public static extern bool ConnectNamedPipe(
                IntPtr hHandle, // handle to named pipe
                Overlapped lpOverlapped // overlapped structure
                );
            [DllImport("kernel32.dll", SetLastError = true)]
            public static extern bool ReadFile(
                IntPtr hHandle, // handle to file
                byte[] lpBuffer, // data buffer
                uint nNumberOfBytesToRead, // number of bytes to read
                byte[] lpNumberOfBytesRead, // number of bytes read
                uint lpOverlapped // overlapped buffer
                );
            [DllImport("kernel32.dll", SetLastError = true)]
            public static extern bool WriteFile(
                IntPtr hHandle, // handle to file
                byte[] lpBuffer,   // data buffer
                uint nNumberOfBytesToWrite, // number of bytes to write
                byte[] lpNumberOfBytesWritten, // number of bytes written
                uint lpOverlapped // overlapped buffer
                );
            [DllImport("kernel32.dll", SetLastError = true)]
            public static extern bool FlushFileBuffers(
                IntPtr hHandle);
            [DllImport("kernel32.dll", SetLastError = true)]
            public static extern bool DisconnectNamedPipe(
                IntPtr hHandle);        [DllImport("kernel32.dll", SetLastError = true)]
            public static extern bool SetNamedPipeHandleState(
                IntPtr hHandle,
                ref uint mode,
                IntPtr cc,
                IntPtr cd);        [DllImport("kernel32.dll", SetLastError = true)]
            public static extern bool WaitNamedPipe(
                String name,
                int timeout);        [DllImport("kernel32.dll", SetLastError = true)]
            public static extern bool CloseHandle(
                IntPtr hHandle);        [DllImport("kernel32.dll", SetLastError = true)]
            public static extern uint GetLastError();    }    [StructLayout(LayoutKind.Sequential)]
        public class Overlapped
        {
        }    [StructLayout(LayoutKind.Sequential)]
        public class SecurityAttributes
        {
        }
    }
      

  2.   

    难怪你会这么慢,C#就有自带的管道通信了呀。 对于你所说的C++封装的不是很了解,我用C#带的那个速度非常快的,没有什么延迟