using System.Collections.Generic; using System.Threading; public class CoffeeMachine { public static Queue Input; public static Queue Output; static Thread Task; public static void SwitchOn() { Input = new Queue(); Output = new Queue(); Task = new Thread( new ThreadStart(Behaviour) ); Task.Start(); } public static void SwitchOff() { Task.Abort(); } static void Behaviour() { const int price = 50; int amount = 0; while(true) { while(Input.Count == 0) Thread.Sleep(100); byte[] bytes = Input.Dequeue(); int i = Convert.ByteArrayToInt(bytes); amount = amount+i; while (amount >= price) { Output.Enqueue(Convert.StringToByteArray("coffee")); amount = amount-price; } } } }