static async Task Main() { Environment.CurrentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); Console.CancelKeyPress += (sender, args) => Environment.Exit(0); var processPool = new ChildProcessPool(); var randomClient = new RandomClient(processPool); while (true) { var value = await randomClient.NextAsync(); Console.WriteLine($"[{DateTime.Now}] Next random number is {value}"); Console.ReadLine(); } }
static async Task Main() { Console.CancelKeyPress += (sender, args) => Environment.Exit(0); var processPool = new ChildProcessPool(); while (true) { using (var childProcessLease = processPool.LeaseProcess()) { var request = new RandomNextRequest() { Id = Guid.NewGuid() }; var response = await childProcessLease.ChildProcess.ExecuteAsync <RandomNextResponse>(request).ConfigureAwait(false); Console.WriteLine($"[{DateTime.Now}] Next random number is {response.Value}"); } Console.ReadLine(); } }
public ChildProcessLease(ChildProcessPool pool, ChildProcess childProcess) { _pool = pool ?? throw new ArgumentNullException(nameof(pool)); ChildProcess = childProcess ?? throw new ArgumentNullException(nameof(childProcess)); }
public RandomClient(ChildProcessPool processPool) { _processPool = processPool ?? throw new ArgumentNullException(nameof(processPool)); }