Beispiel #1
0
        static void Main(string[] args)
        {
            Airline     airline      = new Airline();
            travelAgnet TravelAgnets = new travelAgnet();

            mcb = new MultiCellBuffer(3);

            Thread airlinefunc = new Thread(new ThreadStart(airline.airlineFunc));

            airlinefunc.Start();

            Airline.priceCut += new priceCutEvent(TravelAgnets.ticketOnSale);
            OrderProcessing.orderProcessed += new orderProcessedEvent(TravelAgnets.orderProcessed);
            travelAgnet.orderCreated       += new orderCreateEvent(airline.runOrder);

            travelAgents = new Thread[5];

            for (int i = 0; i < 5; i++)                                                           // N = 5 here
            {                                                                                     //Start N retailer threads
                travelAgents[i]      = new Thread(new ThreadStart(TravelAgnets.travelAgentFunc)); //starts thread with retailer function
                travelAgents[i].Name = (i + 1).ToString();
                travelAgents[i].Start();
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            ChickenFarm chicken      = new ChickenFarm();                                           //chicken object
            Retailer    chickenStore = new Retailer();                                              //retailer object

            mcb = new MultiCellBuffer(3);                                                           //initializes MultiCellBuffer with 3 cells

            Thread chickenFunc = new Thread(new ThreadStart(chicken.chickenFunc));                  //chicken thread

            chickenFunc.Start();                                                                    // starts the chicken thread

            ChickenFarm.priceCut           += new priceCutEvent(chickenStore.chickenOnSale);        //execute chickenOnSale method when price is cut
            Retailer.orderCreated          += new orderCreatedEvent(chicken.runOrder);              //runOrder when the orderCreated event is emitted
            OrderProcessing.orderProcessed += new orderProcessedEvent(chickenStore.orderProcessed); //order processed confirmation callback

            retailers = new Thread[5];                                                              //create 5 threads

            for (int i = 0; i < 5; i++)                                                             // N = 5 here
            {                                                                                       //Start N retailer threads
                retailers[i]      = new Thread(new ThreadStart(chickenStore.retailerFunc));         //starts thread with retailer function
                retailers[i].Name = (i + 1).ToString();
                retailers[i].Start();
            }
        }