Esempio n. 1
0
        /// <summary>
        /// Thread for generating persons
        /// and delegating them to the different gates
        /// </summary>
        protected override void ThreadWork()
        {
            while (true)
            {
                for (int i = 0; i < Counters.Length; i++)
                {
                    CounterDesk curDesk = Counters[i];
                    Monitor.Enter(curDesk.Line.Lock);

                    try
                    {
                        if (!curDesk.IsOpen)
                        {
                            continue;
                        }

                        if (curDesk.Line.IsBufferFull)
                        {
                            continue;
                        }

                        // Create a chance to generate person :)
                        int pRnd = rnd.Next(0, 10000);

                        if (pRnd <= 10)
                        {
                            curDesk.Line.AddToFrontBuffer(PersonFactory.GeneratePerson(curDesk.GateId));
                        }

                        if (curDesk.Line.BufferCounter == 1)
                        {
                            Monitor.PulseAll(curDesk.Line.Lock);
                        }
                    }
                    finally
                    {
                        Monitor.Exit(Counters[i].Line.Lock);
                    }
                }
            }
        }