I checked similar questions but my question seems simpler and straightforward: There are a server and a client and a named pipe between.
The client listens to the messages the server sends (while loop).
How do I detect that the server closed the pipe, so I softly close the client as well?
I saw 3 options:
- Put
pipeHhandle.IsClosed
in thewhile
condition of the listening client loop - Catch
ObjectDisposedException
hoping that it will catch only end of communication and not other failures (This exception does not give exceptionerrorCode
). - Catch
System.ComponentModel.Win32Exception
and check inside the exceptionerrorCode
(-2147467259). Is it standard to put an "if" in catch code?
I did not find any specific exception for "ended pipe" although the program (without catch) does throw an exception whose number is 109 or -2147467259, I am confused.
Thanks for any help.