public void StartBelt(CancellationToken token, ref int crustcount) { while (!token.IsCancellationRequested) { stopbelt.WaitOne(); Thread.Sleep(50); Crust crustdequeue = crustbelt.Dequeue(); crustcount++; Console.WriteLine(crustdequeue.Filling + "gr filling , " + crustdequeue.Flavor + "gr flavor, " + crustdequeue.Topping + "gr topping."); crustbelt.Enqueue(new Crust()); crustready.Set(); } }
public void DoWork() { if (fillinghopper.Body < grfilling) { fillinghopper.Needfilling = true; } if (flavorhopper.Body < grflavor) { flavorhopper.Needfilling = true; } if (toppinghopper.Body < grtopping) { toppinghopper.Needfilling = true; } if (fillinghopper.Needfilling || flavorhopper.Needfilling || toppinghopper.Needfilling) { convbelt.stopbelt.Reset(); hopperevent.Set(); lucyevent.Reset(); lucyevent.WaitOne(); } hopperevent.Reset(); convbelt.stopbelt.Set(); fillinghopper.Needfilling = false; flavorhopper.Needfilling = false; toppinghopper.Needfilling = false; convbelt.crustready.WaitOne(); Crust crust = convbelt.GetCurrentCrust(); lock (locking) { //filling fillinghopper.Body -= grfilling; crust.Filling += grfilling; //flavor flavorhopper.Body -= grflavor; crust.Flavor += grflavor; //topping toppinghopper.Body -= grtopping; crust.Topping += grtopping; } }
public static void Belt(bool isDispensing, ConcurrentBag <Crust> crusts, AutoResetEvent stopLucy, AutoResetEvent waitLucy) { var stopwatch = new Stopwatch(); while (isWorking) { stopwatch.Start(); Crust newCrust = new Crust(); crusts.Add(newCrust); stopLucy.Set(); Spin.Wait(50); if (isDispensing) { waitLucy.WaitOne(); } stopwatch.Stop(); Console.WriteLine("Pie was created successfully!"); Console.WriteLine("Time taken for the pie to be created was {0}." + Environment.NewLine, stopwatch.ElapsedMilliseconds); stopwatch.Reset(); if (stopFactory) { isWorking = false; isStopped = true; } } }
public void AddTopping(Crust crust, Hopper hopper) { crust.Topping = 100; hopper.Content -= 100; Spinning(); }
public void AddFlavour(Crust crust, Hopper hopper) { crust.Flavor = 10; hopper.Content -= 10; Spinning( ); }
public void AddFilling(Crust crust, Hopper hopper) { crust.Filling = 250; hopper.Content -= 250; Spinning(); }