static void Main(string[] args)
        {
            StockController controller = new StockController();
            TimeSpan        workDay    = new TimeSpan(0, 0, 2);

            Task t1 = Task.Run(() => new SalesPerson("Sahil").Work(controller, workDay));
            Task t2 = Task.Run(() => new SalesPerson("Peter").Work(controller, workDay));
            Task t3 = Task.Run(() => new SalesPerson("Juliette").Work(controller, workDay));
            Task t4 = Task.Run(() => new SalesPerson("Xavier").Work(controller, workDay));

            Task.WaitAll(t1, t2, t3, t4);
            controller.DisplayStatus();
        }
Example #2
0
        static void Main()
        {
            var controller = new StockController();
            var workDay    = new TimeSpan(0, 0, 4);

            var t1 = Task.Run(() => new SalesPerson("Sahil").Work(controller, workDay));
            var t2 = Task.Run(() => new SalesPerson("Peter").Work(controller, workDay));
            var t3 = Task.Run(() => new SalesPerson("Juliette").Work(controller, workDay));
            var t4 = Task.Run(() => new SalesPerson("Xavier").Work(controller, workDay));
            var t5 = Task.Run(() => new SalesPerson("Ken").Work(controller, workDay));

            Task.WaitAll(t1, t2, t3, t4, t5);
            controller.DisplayStatus();
        }
        static void Main()
        {
            var controller = new StockController();
            var workDay = new TimeSpan(0, 0, 4);

            var t1 = Task.Run(() => new SalesPerson("Sahil").Work(controller, workDay));
            var t2 = Task.Run(() => new SalesPerson("Peter").Work(controller, workDay));
            var t3 = Task.Run(() => new SalesPerson("Juliette").Work(controller, workDay));
            var t4 = Task.Run(() => new SalesPerson("Xavier").Work(controller, workDay));
            var t5 = Task.Run(() => new SalesPerson("Ken").Work(controller, workDay));

            Task.WaitAll(t1, t2, t3, t4, t5);
            controller.DisplayStatus();
        }
 public void Work(StockController stockController, TimeSpan workDay)
 {
     var rand = new Random(Name.GetHashCode());
     var start = DateTime.Now;
     while (DateTime.Now - start < workDay)
     {
         //Thread.Sleep(rand.Next(100));
         var buy = (rand.Next(6) == 0);
         var itemName = Program.AllShirtNames[rand.Next((Program.AllShirtNames.Count))];
         if (buy)
         {
             var quantity = rand.Next(9) + 1;
             stockController.BuyStock(itemName, quantity);
             //DisplayPurchase(itemName, quantity);
         }
         else
         {
             var success = stockController.TrySellItem(itemName);
             //DisplaySaleAttempt(success, itemName);
         }
     }
     Console.WriteLine("SalesPerson {0} signing off", Name);
 }
Example #5
0
        public void Work(StockController stockController, TimeSpan workDay)
        {
            var rand  = new Random(Name.GetHashCode());
            var start = DateTime.Now;

            while (DateTime.Now - start < workDay)
            {
                //Thread.Sleep(rand.Next(100));
                var buy      = (rand.Next(6) == 0);
                var itemName = Program.AllShirtNames[rand.Next((Program.AllShirtNames.Count))];
                if (buy)
                {
                    var quantity = rand.Next(9) + 1;
                    stockController.BuyStock(itemName, quantity);
                    //DisplayPurchase(itemName, quantity);
                }
                else
                {
                    var success = stockController.TrySellItem(itemName);
                    //DisplaySaleAttempt(success, itemName);
                }
            }
            Console.WriteLine("SalesPerson {0} signing off", Name);
        }