locked
StreamWriter WriteLine() Timeout possible? (Named Pipes) RRS feed

  • Question

  • Hi, I am looking for some sort of timout for the WriteLine() Method of the Streamwriter. Following is the Problem: When I am using a named pipe and the client gets stuck in its program and doesnt get to the point where it could read the messages of the Server, this results in the Server getting stuck. Because the Server sends the message via WriteLine() and waits for the Client to read the message(which it cant) and since the pipe isnt broken there wont be an exception either. --> Server waits infinitely. So is there any possibility to get the WriteLine() Method to timeout after a while?

    Streamwriter.Basestream.WriteTimeout doesnt work for named pipes unfortunately.

    Thanks in advance!

    Friday, October 9, 2020 9:32 AM

All replies

  • What kind of streams or writers are you using? (NamedPipeServerStream?)

    Friday, October 9, 2020 3:11 PM
  • Exactly
    Friday, October 16, 2020 8:19 AM
  • Maybe something like this:

    StreamWriter sw = . . .

    Task t = sw.WriteLineAsync( line );

    if( ! t.Wait( 3000 ) )

    {

       // timeout

       . . .

    }

    Saturday, October 17, 2020 1:46 PM