Пример #1
0
        public async Task Run()
        {
            StockController ctr     = new StockController(TShirtProvider.AllShirts);
            TimeSpan        workDay = new TimeSpan(0, 0, 0, 0, 500);

            Task task1 = Task.Run(() => new SalesPerson("Kim").Work(workDay, ctr));
            Task task2 = Task.Run(() => new SalesPerson("Sahil").Work(workDay, ctr));
            Task task3 = Task.Run(() => new SalesPerson("Chuck").Work(workDay, ctr));

            Task.WaitAll(task1, task2, task3);

            ctr.DisplayStock();
        }
Пример #2
0
        public void Work(TimeSpan workDay, StockController ctr)
        {
            DateTime start = DateTime.Now;

            while (DateTime.Now - start < workDay)
            {
                var result = ServeCustomer(ctr);

                if (result.Status != null)
                {
                    Console.WriteLine($"{Name}: {result.Status}");
                }
                if (!result.ShirtInStock)
                {
                    break;
                }
            }
        }