Example #1
0
        static void Main(string[] args)
        {
            StockController controller  = new StockController();
            TimeSpan        workDay     = new TimeSpan(0, 0, 0, 0, 500);
            StaffRecords    staffLogs   = new StaffRecords();
            LogTradesQueue  tradesQueue = new LogTradesQueue(staffLogs);

            SalesPerson[] staff =
            {
                new SalesPerson("Sahil"),
                new SalesPerson("Julie"),
                new SalesPerson("Kim"),
                new SalesPerson("Chuck")
            };
            List <Task> salesTasks = new List <Task>();

            foreach (SalesPerson person in staff)
            {
                salesTasks.Add(
                    Task.Run(() => person.Work(workDay, controller, tradesQueue)));
            }

            Task[] loggingTasks =
            {
                Task.Run(() => tradesQueue.MonitorAndLogTrades()),
                Task.Run(() => tradesQueue.MonitorAndLogTrades())
            };

            Task.WaitAll(salesTasks.ToArray());
            tradesQueue.SetNoMoreTrades();
            Task.WaitAll(loggingTasks);

            controller.DisplayStock();
            staffLogs.DisplayCommissions(staff);
        }
Example #2
0
        static void Main(string[] args)
        {
            StockController controller = new StockController();
            TimeSpan        workDay    = new TimeSpan(0, 0, 0, 0, 500);

            controller.DisplayStock();

            Task t1 = Task.Run(() => new SalesPerson("Amiel").Work(workDay, controller));
            Task t2 = Task.Run(() => new SalesPerson("Talya").Work(workDay, controller));
            Task t3 = Task.Run(() => new SalesPerson("David").Work(workDay, controller));

            Task.WaitAll(t1, t2, t3);

            controller.DisplayStock();

            Console.ReadKey();
        }
Example #3
0
        static void Main(string[] args)
        {
            StockController controller = new StockController();
            TimeSpan        workDay    = new TimeSpan(0, 0, 0, 0, 500);

            Task task1 = Task.Run(() => new SalesPerson("Tim").Work(workDay, controller));
            Task task2 = Task.Run(() => new SalesPerson("Koffi").Work(workDay, controller));
            Task task3 = Task.Run(() => new SalesPerson("Julie").Work(workDay, controller));
            Task task4 = Task.Run(() => new SalesPerson("Michael").Work(workDay, controller));

            Task.WaitAll(task1, task2, task3, task4);

            controller.DisplayStock();
        }