Esempio n. 1
0
        public void TicketAgencyFunc()
        {
            ThemePark park = new ThemePark();

            for (int i = 0; i < 10; i++)
            {
                Thread.Sleep(1000);
                int price = park.getPrice();
                Console.WriteLine("Theme Park {0} has everyday low price of ${1} each ticket", Thread.CurrentThread.Name, price);
            }
        }
Esempio n. 2
0
 public void ThemeParkFunc()
 {
     for (int i = 0; i < 50; i++)
     {
         Thread.Sleep(500);
         // Take the order from the queue of the orders;
         // Decide the price based on the orders
         int newTicketPrice = priceChange.Next(5, 10);
         Console.WriteLine("New Price is {0}", newTicketPrice);
         ThemePark.ChangePrice(newTicketPrice);
     }
 }
Esempio n. 3
0
        static void Main(string[] args)
        {
            ThemePark disneyLand     = new ThemePark();
            Thread    processTickets = new Thread(new ThreadStart(disneyLand.ThemeParkFunc));

            processTickets.Start(); // start one consumer thread
            processTickets.Name = "processTickets";

            TicketAgency touristCenter = new TicketAgency();

            ThemePark.priceCut += new priceCutEvent(touristCenter.TicketOnSale);

            Thread[] ticketAgencies = new Thread[3];
            for (int i = 0; i < 3; i++)
            {
                // Start n ticketAgency threads
                ticketAgencies[i]      = new Thread(new ThreadStart(touristCenter.TicketAgencyFunc));
                ticketAgencies[i].Name = (i + 1).ToString();
                ticketAgencies[i].Start();
            }
        }