static void Main(string[] args)
        {
            Console.CancelKeyPress += (sender, _) => Environment.Exit(0);

            var mainIpcId       = new Guid(args[0]);
            var ownIpcId        = new Guid(args[1]);
            var parentProcessId = Int32.Parse(args[2]);

            TerminateOnParentExit(parentProcessId);

            var ipcClient = new NamedPipesClient(ownIpcId, mainIpcId);
            var random    = new Random();

            ipcClient.Received <RandomNextRequest>()
            .Subscribe(async req =>
            {
                Console.WriteLine($"[{DateTime.Now}] Request received.");

                var value    = random.Next();
                var response = new RandomNextResponse(req.Id, value);
                await ipcClient.SendAsync(response).ConfigureAwait(false);
            });

            Console.ReadLine();
        }
Example #2
0
        public async Task <TResponse> ExecuteAsync <TResponse>(IRequest request, CancellationToken cancellationToken = default)
            where TResponse : IResponse
        {
            var responseTask = _ipcClient.Received <TResponse>()
                               .Where(resp => resp.RequestId == request.Id)
                               .Timeout(TimeSpan.FromSeconds(5))
                               .FirstOrDefaultAsync()
                               .ToTask(cancellationToken);

            await _ipcClient.SendAsync(request, cancellationToken).ConfigureAwait(false);

            return(await responseTask.ConfigureAwait(false));
        }