private static async Task RandomNextDemo()
        {
            var serverIpc = new NamedPipesClient();
            var random    = new Random();
            var server    = new MyNativeLibServer(serverIpc, random);

            server.Start();

            // -----------------

            var clientIpc = new NamedPipesClient(serverIpc.PeerId, serverIpc.OwnId);
            var client    = new NamedPipesRequestResponseClient(clientIpc);

            //-----------------

            while (true)
            {
                var request = new RandomNextRequest()
                {
                    Id = Guid.NewGuid()
                };

                var response = await client.ExecuteAsync <RandomNextResponse>(request).ConfigureAwait(false);

                Console.WriteLine($"[{DateTime.Now}] Next random number is {response.Value}");

                Console.ReadLine();
            }
        }
Esempio n. 2
0
        public async Task <int> NextAsync(CancellationToken cancellationToken = default)
        {
            var request = new RandomNextRequest()
            {
                Id = Guid.NewGuid()
            };

            var responseTask = _ipcClient.Received <RandomNextResponse>()
                               .Where(resp => resp.RequestId == request.Id)
                               .Timeout(TimeSpan.FromSeconds(5))
                               .FirstOrDefaultAsync()
                               .ToTask(cancellationToken);

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

            var response = await responseTask.ConfigureAwait(false);

            return(response.Value);
        }