Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            const int numThreads = 5;
            TollBooth tollBooth  = new TollBooth();

            Thread[] threads = new Thread[numThreads];
            for (int i = 0; i < numThreads; i++)
            {
                Vehicle vehicle = new Vehicle(i);
                threads[i] = new Thread(() => vehicle.Drive(tollBooth));
            }

            foreach (var thread in threads)
            {
                thread.Start();
            }

            foreach (var thread in threads)
            {
                thread.Join();
            }

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
Ejemplo n.º 2
0
 public void Drive(TollBooth tollBooth)
 {
     StartJourney();
     DriveToTollBooth();
     RunIntoTollBooth(tollBooth);
     ExitTollBooth();
     CrossBridge();
 }
Ejemplo n.º 3
0
 private void RunIntoTollBooth(TollBooth tollBooth)
 {
     tollBooth.AcceptPayment(this);
 }