3

我有两个应用程序,我使用命名管道在它们之间进行通信。由于代码项目文章,管道工作得非常好。但我注意到,如果两个应用程序都没有启动。应用程序'A'一直在等待应用程序'B'并且应用程序'A'没有启动。以下是创建 aync 管道的片段:

            NamedPipeServerStream pipeServer = new NamedPipeServerStream(PipeName, PipeDirection.In, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);

            pipeServer.BeginWaitForConnection(new AsyncCallback(WaitForConnectionCallBack), pipeServer);

这与我在应用程序“A”和“B”中创建管道的方式相同,每个应用程序也都有一个客户端。这是我从客户端发送消息的方式:

NamedPipeClientStream pipeStream = new NamedPipeClientStream(".", PipeName, PipeDirection.Out, PipeOptions.Asynchronous);

            // The connect function will indefinitely wait for the pipe to become available
            // If that is not acceptable specify a maximum waiting time (in ms)
            pipeStream.Connect(TimeOut);

            byte[] _buffer = Encoding.UTF8.GetBytes(SendStr);
            pipeStream.BeginWrite(_buffer, 0, _buffer.Length, AsyncSend, pipeStream);

那么如何提高性能以使两个应用程序无需等待即可运行?截至目前,我一直保持 1000 毫秒的超时。我应该减少超时时间吗?或者我错过了什么,看起来很可能:)

4

0 回答 0