public void Run()
        {
            _clientFactory = IfWantToPassParameters() ? new ClientFactory(LoadParameters()) : new ClientFactory();
            _queue         = new SyncQueue <Client>(_maxQueueSize);
            _barber        = new Barber(_queue, _clientsPerDay);

            using (var clientsTokenSource = new CancellationTokenSource())
            {
                var barberTask = Task.Factory.StartNew(_barber.Work);
                _cancellationToken = clientsTokenSource.Token;
                var clientsTask = Task.Factory.StartNew(SimulateQueue, clientsTokenSource.Token);

                barberTask.Wait();
                clientsTokenSource.Cancel();
                clientsTask.Wait();
            }

            Console.WriteLine("End of the day");
            Console.ReadKey();
        }
예제 #2
0
 public Barber(SyncQueue <Client> queue, int clientsPerDay)
 {
     _queue         = queue;
     _clientsPerDay = clientsPerDay;
 }