Reputation: 3373
I'd like to use NamedPipeClientStream
:
var _Pipe = new NamedPipeClientStream(".", "test-a", PipeDirection.In);
_Pipe.Connect();
Unfortunately, there is no way to pass Cancellation token. So, how to cancel connection? I don't want to pass timeout - my client needs to wait "forever" until connection is successful or cancel is requested. ConnectAsync
is not available.
EDIT: I am using .NET Frameowkr 4.5.2 Class library, and there is no such a method like ConnectAsync (only Connect is available).
Upvotes: 1
Views: 1179
Reputation: 21946
To cancel, call Close() or Dispose() method on that pipe. If you'll need to retry later, just create another pipe for that.
I’m 90% sure the thread that was sleeping on that Connect() call will wake up immediately, and fail with some exception. Probably ObjectDisposedException if you call Dispose, or some "The pipe is being closed." Win32 exception if you call Close().
I have never tested with pipes specifically, but that’s what usually happens in Windows with blocking I/O calls for files and sockets.
Upvotes: 1