public override Task ListenAsync(CancellationToken cancellationToken = default(CancellationToken)) { NamedPipeOptions options = ServiceProvider.GetRequiredService <NamedPipeOptions>(); var threads = new Thread[options.ThreadCount]; for (int i = 0; i < threads.Length; i++) { threads[i] = new Thread(StartServerThread); threads[i].Start(cancellationToken); } return(Task.Factory.StartNew(() => { _logger.LogDebug($"Endpoint '{Name}' listening on pipe '{PipeName}'..."); while (!cancellationToken.IsCancellationRequested) { Thread.Sleep(100); for (int i = 0; i < threads.Length; i++) { if (threads[i].Join(250)) { // thread is finished, starting a new thread threads[i] = new Thread(StartServerThread); threads[i].Start(cancellationToken); } } } })); }
public override void Listen() { NamedPipeOptions options = ServiceProvider.GetRequiredService <NamedPipeOptions>(); var threads = new Thread[options.ThreadCount]; for (int i = 0; i < threads.Length; i++) { threads[i] = new Thread(StartServerThread); threads[i].Start(); } while (true) { Thread.Sleep(100); for (int i = 0; i < threads.Length; i++) { if (threads[i].Join(250)) { // thread is finished, starting a new thread threads[i] = new Thread(StartServerThread); threads[i].Start(); } } } }
public override void Listen() { NamedPipeOptions options = ServiceProvider.GetRequiredService <NamedPipeOptions>(); List <Task> tasks = new List <Task>(); // Add additional waiters if requested for (int i = 1; i < options.ThreadCount; i++) { tasks.Add(StartServerThread(null)); } // Loop until cancellation, restart new waiter as soon as one finished while (!cancellationToken.IsCancellationRequested) { tasks.Add(StartServerThread(null)); Task <Task> t = Task.WhenAny(tasks); try { t.Wait(cancellationToken.Token); tasks.Remove(t.Result); } catch (OperationCanceledException) { } } }
public NamedPipeIpcServiceEndpoint(string name, IServiceProvider serviceProvider, string pipeName) : base(name, serviceProvider) { PipeName = pipeName; _logger = serviceProvider.GetService <ILogger <NamedPipeIpcServiceEndpoint <TContract> > >(); _options = serviceProvider.GetRequiredService <NamedPipeOptions>(); }