I’m looking for a way to communicate between programs on the same computer, and have been referred to Named P开发者_如何学Pythonipes.
It seems that the only way to connect the server is though WaitForConnection (I don’t know enough to use unmanaged code). But if no one connects to the network – the program hangs indefinitely. How do I make a connection with a timeout limit?
Thanks.
Instead of calling the synchronous WaitForConnection method, call BeginWaitForConnection/EndWaitForConnection for a non-blocking server. See here for a similar answer.
The constructor you want is the one with 5 parameters here. You can call it like so:
NamedPipeServerStream pipeServer = new NamedPipeServerStream(
"<pipe-name>",
PipeDirection.InOut,
1,
PipeTransmissionMode.Byte,
PipeOptions.Asynchronous);
精彩评论