static void Main(string[] args) { Ferry mainFerry = new Ferry(); mainFerry.FerryThread.Start(); Car[] cars = new Car[Ferry.CarsCount]; for (int i = 0; i < Ferry.CarsCount; ++i) { cars[i] = new Car(); cars[i].Index = i+1; cars[i].Ferry = mainFerry; cars[i].CarThread.Start(); } mainFerry.FerryThread.Join(); for (int i = 0; i < Ferry.CarsCount; ++i) { cars[i].CarThread.Join(); } Console.WriteLine("Ended"); Console.ReadLine(); }
static void Main(string[] args) { Ferry mainFerry = new Ferry(); mainFerry.FerryThread.Start(); Car[] cars = new Car[Ferry.CarsCount]; for (int i = 0; i < Ferry.CarsCount; ++i) { cars[i] = new Car(); cars[i].Index = i + 1; cars[i].Ferry = mainFerry; cars[i].CarThread.Start(); } mainFerry.FerryThread.Join(); for (int i = 0; i < Ferry.CarsCount; ++i) { cars[i].CarThread.Join(); } Console.WriteLine("Ended"); Console.ReadLine(); }
private void GetOnFerry() { if (Ferry.CanCarTakeAction(this)) { Console.WriteLine(string.Format("Car {0} get on the Ferry", Index)); //Ferry.GetCarIn(this); CarState = CarEnum.OnFerry; } WaitForAccess(); }
private void MoveFromFerry() { if (Ferry.CanCarTakeAction(this)) { Console.WriteLine(string.Format("Car {0} get out of the Ferry", Index)); //Ferry.GetCarOut(this); } else { WaitForAccess(); } }