3

2 つのアプリケーションがあり、それらの間の通信に名前付きパイプを使用しました。コード プロジェクトの記事のおかげで、パイプは問題なく動作しています。しかし、両方のアプリが起動しない場合に気付きました。アプリケーション「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