using System.Threading.Tasks;
await new Duplex().RunAsync();
public async Task RunAsync()
var bobPipe = new NamedPipeServerStream("JsonRpcDuplex", PipeDirection.InOut, maxNumberOfServerInstances: 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
var sallyPipe = new NamedPipeClientStream(".", "JsonRpcDuplex", PipeDirection.InOut, PipeOptions.Asynchronous);
await Task.WhenAll(bobPipe.WaitForConnectionAsync(), sallyPipe.ConnectAsync()).ConfigureAwait(false);
await Task.WhenAll(this.DoBob(bobPipe), this.DoSally(sallyPipe));
async Task DoBob(Stream pipe)
CancelLocallyInvokedMethodsWhenConnectionIsClosed = true
rpc.AddLocalRpcTarget<IBob>(new Bob(), null);
var sally = rpc.Attach<ISally>();
async Task DoSally(Stream pipe)
CancelLocallyInvokedMethodsWhenConnectionIsClosed = true
rpc.AddLocalRpcTarget<ISally>(new Sally(), null);
var bob = rpc.Attach<IBob>();
Console.WriteLine("Bob eats");
return Task.CompletedTask;
public class Sally : ISally
Console.WriteLine("Sally drinks");
return Task.CompletedTask;