public void Consume() { while (true) { Thread.Sleep(200); int ramase; Cadou cadou = broker.Get(out ramase); if (cadou == null && broker.State == 1) { break; } if (cadou != null) { Console.WriteLine(string.Format("Cadou cu id {0}, nume: {1}, descriere {2}, Consumer: {3}", cadou.Id, cadou.Name, cadou.Description, myId)); Console.WriteLine("Ramase: " + ramase); } } }
public void Produce() { int i = 0; while (i < MAX) { Random random = new Random(); int rnd = random.Next(); var cadou = new Cadou() { Id = rnd, Description = "Cadoul cu id: " + rnd, Name = "Cadou" + rnd }; broker.Add(cadou); i++; } broker.State = 1; }
public void Add(Cadou cadou) { cadouri.Enqueue(cadou); }