Exemple #1
0
        //Work with buyer
        private void  Work()
        {
            while (stand.IsOpen)
            {
                if (!stand.Buyers.TryDequeue(out curr))
                {
                    //if queue to stand is empty seller want to have a rest
                    Thread.Sleep(100);
                    continue;
                }

                Thread.Sleep(Helper.rnd.Next(10, 50));


                //lost some buyers:(
                if (curr == null)
                {
                    System.Console.WriteLine("rip"); return;
                }



                int buy = curr.Buy(stand.StandProduct);
                Interlocked.Add(ref stand.Selled, buy);
                Interlocked.Increment(ref stand.RIPBuyers);
                curr.CallToQueue();
            }
        }
Exemple #2
0
 //Add new buyer
 public void Add(Buyer buyer)
 {
     //Console.WriteLine("Add new buyer");
     buyer.ToQueue += ToQueue;
     buyer.CallToQueue();
 }