I'm currently looking at .NET 6 compatible alternatives to WCF with Named Pipes for local IPC, and this one seems like a good fit (that doesn't require a lot of changes, other than writing a quick serializer based on the NetDataContractSerializer).
However, one of the things I do a lot is simply try and connect to the server - and do nothing if there's no server. In WCF, i simply use the open timeout and wait for it to fail, but PipeClient has no such overload.
NamedPipeClientStreamdoes have ConnectAsync overloads that accept a timeout value (in milliseconds), but they're not exposed in PipeClient.
I can work around it like this:
var client = new PipeClient<IServerContract>(new NetJsonPipeSerializer(), ServerPipeName);
var cts = new CancellationTokenSource(millisecondsDelay: 200);
try
{
await client.ConnectAsync(cts.Token);
// do things when the connection succeeds.
}
catch (OperationCanceledException)
{
// no server (or too slow to respond), keep going without a server.
}
...but it would certainly feel nicer if I could just explicitly call client.ConnectAsync(timeout: 200) there (without abusing the CancellationToken for it).
Won't really help me get rid of the try/catch (since I'm assuming you'd simply pass on the TimeoutException from the pipe), but would free up the CancellationToken for other things.
I'm currently looking at .NET 6 compatible alternatives to WCF with Named Pipes for local IPC, and this one seems like a good fit (that doesn't require a lot of changes, other than writing a quick serializer based on the
NetDataContractSerializer
). However, one of the things I do a lot is simply try and connect to the server - and do nothing if there's no server. In WCF, i simply use the open timeout and wait for it to fail, butPipeClient
has no such overload.NamedPipeClientStream
does haveConnectAsync
overloads that accept a timeout value (in milliseconds), but they're not exposed inPipeClient
.I can work around it like this:
...but it would certainly feel nicer if I could just explicitly call
client.ConnectAsync(timeout: 200)
there (without abusing theCancellationToken
for it). Won't really help me get rid of thetry
/catch
(since I'm assuming you'd simply pass on theTimeoutException
from the pipe), but would free up theCancellationToken
for other things.