Esempio n. 1
0
        private void Pessoa_ProdutorPilha(Pessoa pessoa)
        {
            if (!PilhaLivre.Any())
            {
                Produtor.Enqueue(pessoa);
                return;
            }
            UsrFila fila = PilhaLivre.Dequeue();

            if (fila == null)
            {
                return;
            }
            fila.SetaEstado(true);
            pessoa.Reinicia();
            PilhaOcupada.Enqueue(fila);
            EventoConsumidor();
        }
Esempio n. 2
0
 /// <summary>
 /// Inicializa quantidade de produtores,consumidores e fila
 /// </summary>
 private void Inicializa()
 {
     //inicializa produtores
     for (int i = 0; i < _qteProdutor; i++)
     {
         //cria produtor
         Pessoa pessoa = new Pessoa(_prodaleatorio ? GetRandom(_tpProdutor) : _tpProdutor);
         pessoa.ExecutaPilha += Pessoa_ProdutorPilha;
         LstProdutor.Add(pessoa);
         //define localização do produtor no painel
         pessoa.Location = new Point(width, height);
         PlProdutor.Controls.Add(pessoa);
         width += pessoa.Width;
         if (width >= 800)
         {
             width   = 0;
             height += pessoa.Height;
         }
     }
     PlProdutor.Height = (height == 0 ? 92 : height + 92) + 10;
     height            = 0;
     width             = 0;
     //inicializa consumidores
     for (int i = 0; i < _qteConsumidor; i++)
     {
         //cria consumidor
         Pessoa pessoa = new Pessoa(_consaleatorio  ? GetRandom(_tpConsumidor) : _tpConsumidor);
         pessoa.ExecutaPilha += Pessoa_ConsomePilha;
         LstConsumidor.Add(pessoa);
         //define localização do consumidor no painel
         pessoa.Location = new Point(width, height);
         PlConsumidor.Controls.Add(pessoa);
         width += pessoa.Width;
         if (width >= 800)
         {
             width   = 0;
             height += pessoa.Height;
         }
     }
     PlConsumidor.Height = (height == 0 ? 92 : height + 92) + 10;
     height = 0;
     width  = 0;
     for (int i = 0; i < _fila; i++)
     {
         //cria posição da fila
         UsrFila fila = new UsrFila(i);
         fila.SetaEstado(false);
         PilhaLivre.Enqueue(fila);
         LstFilas.Add(fila);
         //define posição da fila no painel
         fila.Location = new Point(width, height);
         PlFila.Controls.Add(fila);
         width += fila.Width;
         if (width >= 800)
         {
             width   = 0;
             height += fila.Height;
         }
     }
     PlFila.Height = (height == 0 ? 92 : height + 92) + 10;
 }