Esempio n. 1
0
 public MainCashiers()
 {
     for (int i = 0; i < cashiers.Length; i++)
     {
         cashiers[i] = new Cashier();
         cashiers[i].NumOfCashier = i;
     }
 }
Esempio n. 2
0
 public SuperMarketQueue(int numOfCashiers)
 {
     front    = rear = null;
     cashiers = new Cashier[numOfCashiers];
     for (int i = 0; i < cashiers.Length; i++)
     {
         cashiers[i] = new Cashier();
         cashiers[i].NumOfCashier = i;
     }
 }
Esempio n. 3
0
 public SuperMarket(int numOfCashiers)
 {
     blockingCollection = new BlockingCollectionQueue(numOfCashiers);
     cashiers           = new Cashier[numOfCashiers];
     for (int i = 0; i < cashiers.Length; i++)
     {
         cashiers[i] = new Cashier();
         cashiers[i].NumOfCashier = i;
     }
 }
Esempio n. 4
0
 public PCQueue(int workerCount)
 {
     cashiers  = new Thread[workerCount];
     _cashiers = new Cashier[workerCount];
     // Create and start a separate thread for each cashier
     for (int i = 0; i < workerCount; i++)
     {
         (cashiers[i] = new Thread(Consume)).Start();
         _cashiers[i] = new Cashier {
             NumOfCashier = i
         };
     }
 }
Esempio n. 5
0
        public BlockingCollectionQueue(int numOfCashiers)
        {
            cashiers = new Cashier[numOfCashiers];
            for (int i = 0; i < cashiers.Length; i++)
            {
                cashiers[i] = new Cashier();
                cashiers[i].NumOfCashier = i;
            }
            var thread = new Thread(new ThreadStart(OnStart));

            thread.Start();
            //AddPersonToCashier();
        }
Esempio n. 6
0
        internal void AddPersonToCashier()
        {
            var emptyCashier = from c in cashiers
                               where c.CurrPerson == null
                               select c;
            Cashier cash = emptyCashier.FirstOrDefault();

            Console.WriteLine("number of occupied cashiers: {0}", cashiers.Length - emptyCashier.Count());
            if (cash != null)
            {
                cash.AddCurrPerson(front.data);
                Dequeue();
            }
        }
Esempio n. 7
0
 private void OnStart()
 {
     while (true)
     {
         id++;
         Enqueue(new Person {
             Id = id, Name = "Person" + id
         });
         Thread.Sleep(1000);
         var emptyCashier = from c in cashiers
                            where c.CurrPerson == null
                            select c;
         Cashier cash = emptyCashier.FirstOrDefault();
         if (cash != null)
         {
             Person p = Dequeue();
             // Call the Event
             //ev_AddPerson?.Invoke(this, p);
             cash.AddCurrPerson(p);
         }
     }
 }