public R Request(S obj) { using (var client = new NamedPipeClientStream(ServerName, PipeName)) { client.Connect(); Formatter.Serialize(client, obj); OnRequestSended?.Invoke(this, obj); var response = Formatter.Deserialize <R>(client); OnResponseReceived?.Invoke(this, response); return(response); } }
public async Task <R> RequestAsync(S obj, CancellationToken cancellationToken) { using (var client = new NamedPipeClientStream(ServerName, PipeName)) { await client.ConnectAsync(cancellationToken); Formatter.Serialize(client, obj); OnRequestSended?.Invoke(this, obj); var response = Formatter.Deserialize <R>(client); OnResponseReceived?.Invoke(this, response); return(response); } }