1

I’m looking for a way to communicate between programs on the same computer, and have been referred to Named Pipes.

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.

ispiro
  • 26,556
  • 38
  • 136
  • 291

1 Answers1

2

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);
Community
  • 1
  • 1
Brent M. Spell
  • 2,257
  • 22
  • 14