if (i >= ATTEMPTS) { handle.State = InterProcessConnectionState.Error; throw new NamedPipeIOException("Error creating named pipe"+name+".Internalerror:"+NamedPipeNative.GetLastError().ToString(),NamedPipeNative.GetLastError()); } } returnhandle; } 通过调用NamedPipeNative.CreateNamedPipe方法,上面的方法创建了一个双方互通的命名管道,并且指定管道可以有无限制的实例。常量的名称都是英语,不难看懂,就不一一解释了。
if (handle.Handle.ToInt32() != NamedPipeNative.INVALID_HANDLE_VALUE){ // The client managed to connect to the server pipe handle.State = InterProcessConnectionState.
ConnectedToServer; // Set the read mode of the pipe channel uint mode = NamedPipeNative.PIPE_READMODE_MESSAGE;