if (i >= ATTEMPTS) { handle.State = InterProcessConnectionState.Error; throw new NamedPipeIOException("Error creating named pipe"+name+".Internalerror:"+NamedPipeNative.GetLastError().ToString(),NamedPipeNative.GetLastError()); } } returnhandle; } 通過(guò)調(diào)用NamedPipeNative.CreateNamedPipe方法,上面的方法創(chuàng)建了一個(gè)雙方互通的命名管道,并且指定管道可以有無(wú)限制的實(shí)例。常量的名稱都是英語(yǔ),不難看懂,就不一一解釋了。
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;