public void farmerFunc() { for (Int32 i = 0; i < 50; i++) { Thread.Sleep(500); //Take order from the queue of the orders //Decide the price based on the orders Int32 p = rng.Next(5, 10); //Console.WriteLine("New Price is {0}", p); ChickenFarm.changePrice(p); } }
public void retailerFunc() { ChickenFarm chicken = new ChickenFarm(); price = chicken.getPrice(); Console.WriteLine("Store{0} initial chicken Price: {1}", Thread.CurrentThread.Name, price); while (true) { if (needorder == true) { OrderClass order = new OrderClass(); order.SenderId = Thread.CurrentThread.Name; order.CardNo = 5000 + int.Parse(Thread.CurrentThread.Name); order.Amount = 25; String encodedorder = Encoder.Encode(order); orderSent = DateTime.Now.TimeOfDay; myApplication.buffer.setOneCell(encodedorder); needorder = false; } } }
static void Main(string[] args) { /* OrderClass order = new OrderClass(); * order.SenderId = "Jesse"; * order.CardNo = 5155; * order.Amount = 10094; * String encoded = Encoder.Encode(order); * OrderClass decodedOrder = Decoder.Decode(encoded); * OrderProcessing.confirmOrder(decodedOrder, 7); * ChickenFarm chicken = new ChickenFarm(); * while(true) * { * Thread.Sleep(500); * chicken.PricingModel(); * } */ ChickenFarm chicken = new ChickenFarm(); Thread farmer = new Thread(new ThreadStart(chicken.PricingModel)); farmer.Start(); Retailer store = new Retailer(); //Thread calc = new Thread(new ThreadStart(store.chicken.PricingModel)); //calc.Start(); ChickenFarm.priceCut += new priceCutEvent(store.chickenOnSale); Thread[] retailers = new Thread[5]; for (int i = 0; i < 5; i++) { retailers[i] = new Thread(new ThreadStart(store.retailerFunc)); retailers[i].Name = (i + 1).ToString(); retailers[i].Start(); } /* * ChickenFarm chicken = new ChickenFarm(); * Thread farmer = new Thread(new ThreadStart(chicken.PricingModel)); * farmer.Start(); * Retailer chickenstore = new Retailer(); * ChickenFarm.priceCut += new priceCutEvent(chickenstore.chickenOnSale); * Thread[] retailers = new Thread[5]; * for (int i = 0; i < 5; i++) * { * retailers[i] = new Thread(new ThreadStart(chickenstore.retailerFunc)); * retailers[i].Name = (i + 1).ToString(); * retailers[i].Start(); * while (!retailers[i].IsAlive) ; * } */ /* * ChickenFarm chicken = new ChickenFarm(); * Thread farmer = new Thread(new ThreadStart(chicken.farmerFunc)); * farmer.Start(); * Retailer chickenstore = new Retailer(); * ChickenFarm.priceCut += new priceCutEvent(chickenstore.chickenOnSale); * Thread[] retailers = new Thread[5]; * for (int i = 0; i < 5; i++) * { * retailers[i] = new Thread(new ThreadStart(chickenstore.retailerFunc)); * retailers[i].Start(); * } */ }