开发者

How to use Named Pipes without the computer hanging if no one connects to the network?

开发者 https://www.devze.com 2023-04-08 01:44 出处:网络
I’m looking for a way to communicate between programs on the same computer, and have been referred to Named P开发者_如何学Pythonipes.

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消