System.IO.Exception: Pipe is broken

后端 未结 3 870
夕颜
夕颜 2021-02-02 11:20

I have two .NET applications that talk to each other over a named pipe. Everything is great the first time through, but after the first message is sent, and the server is going

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-02 11:53

    The problem for me has occurred when I would call pipe.WaitForConnection() from the server, after the client disconnected. The solution is to catch the IOException and call pipe.Disconnect(), and then call pipe.WaitForConnection() again:

    while (true)
    {
        try
        {
            _pipeServer.WaitForConnection();
            break;
        }
        catch (IOException)
        {
            _pipeServer.Disconnect();
            continue;
        }            
     }
    

提交回复
热议问题