I am using the following code snippet to send data over a Named Pipe in :
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);
}
}
Sometimes, I receive the following error :
System.IO.IOException: The semaphore timeout period has expired.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.Pipes.NamedPipeClientStream.Connect(Int32 timeout)
[...]
I am not sure when this happens (nobody listening to the other side ?) BUT in any case I don't understand why this error is not caught by the try catch block.
Do you have any idea of what is happening ? Any help is welcome.
Try this.
try
{
NamedPipeClientStream pipeStream = new NamedPipeClientStream(".", "TestPipe1234", PipeDirection.Out, PipeOptions.Asynchronous);
pipeStream.Connect(timeOut);
pipeStream.BeginWrite(message, 0, message.Length, aSyncSend, pipeStream);
}
catch (Exception)
{
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.