【问题标题】:Error with Named Pipes is not caught in try/catch命名管道的错误未在 try/catch 中捕获
【发布时间】:2016-10-19 10:17:14
【问题描述】:

我正在使用以下代码 sn-p 通过命名管道发送数据:

public void send(byte[] message, int timeOut = 1000)
{
    try
    {
        NamedPipeClientStream pipeStream = new NamedPipeClientStream(".", "TestPipe1234", PipeDirection.Out, PipeOptions.Asynchronous);

        pipeStream.Connect(timeOut);
        pipeStream.BeginWrite(message, 0, message.Length, aSyncSend, pipeStream);
    }
    catch (TimeoutException ex)
    {
        Debug.WriteLine(ex.Message);
    }
}

有时,我会收到以下错误:

System.IO.IOException:信号量超时期限已过。

在 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)

在 System.IO.Pipes.NamedPipeClientStream.Connect(Int32 超时)

[...]

我不确定什么时候会发生这种情况(没有人在听对方说话?)但无论如何我不明白为什么这个错误没有被 try catch 块捕获。

你知道发生了什么吗?欢迎任何帮助。

【问题讨论】:

  • 使用简单的捕获。捕捉(异常){}

标签: c# pipe try-catch named-pipes


【解决方案1】:

试试这个。

try
{
    NamedPipeClientStream pipeStream = new NamedPipeClientStream(".", "TestPipe1234", PipeDirection.Out, PipeOptions.Asynchronous);

    pipeStream.Connect(timeOut);
    pipeStream.BeginWrite(message, 0, message.Length, aSyncSend, pipeStream);
}
catch (Exception)
{
}

【讨论】:

    猜你喜欢
    • 2016-05-21
    • 2014-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多