// Méthodes qui permet d'attribuer le travail aux cuisiniers //private void WorkScheduling() //{ // Console.WriteLine("Le Chef de Cuisine récupère les commandes et assigne les plats à ses cuisiniers"); // while (true) // { // while (waitCommande.Count > 0) // { // CommandePaquet commande = waitCommande.Peek(); // for (int i = 0; i < waitCommande.Peek().ListPlats.Count; i++) // { // int PlatsSend = waitCommande.Peek().ListPlats.ElementAt(i); // //Console.WriteLine(commande.ListPlats.Count); // Cooker cookerChoisis = this.ChooseCooker(); // Thread th = new Thread(() => cookerChoisis.MakeDish(PlatsSend)); // th.Start(); // } // //kitchenDesk.ListCommandeSend.Add(waitCommande.Peek()); // waitCommande.Dequeue(); // } // Thread.Sleep(100); // } //} private void WorkScheduling() { Console.WriteLine("Le Chef de Cuisine récupère les commandes et assigne les plats à ses cuisiniers"); while (true) { if (waitCommande.Count > 0) { //CommandePaquet commande = waitCommande.Peek(); Thread[] thPlats = new Thread[waitCommande.Peek().ListPlats.Count]; for (int i = 0; i < thPlats.Length; i++) { int PlatsSend = waitCommande.Peek().ListPlats.ElementAt(i); Cooker cookerChoisis = this.ChooseCooker(); thPlats[i] = new Thread(() => cookerChoisis.MakeDish(PlatsSend)); thPlats[i].Start(); } foreach (var thread in thPlats) { thread.Join(); } kitchenDesk.ListCommandeSend.Add(waitCommande.Peek()); Console.WriteLine("Liste CommandeSend : {0}", kitchenDesk.ListCommandeSend.Count); waitCommande.Dequeue(); } Thread.Sleep(100); } }
public Chef(Cooker cuisinier1, Cooker cuisinier2, Desk kitchenDesk) { sprite = new Sprite(imageChef, xPositionInit, yPositionInit, widthInit, heightInit); waitCommande = new Queue <CommandePaquet>(); listCuisiniers = new List <Cooker>(); listCuisiniers.Add(cuisinier1); listCuisiniers.Add(cuisinier2); this.kitchenDesk = kitchenDesk; Thread thWorkScheduling = new Thread(WorkScheduling); thWorkScheduling.Start(); }