Exemplo n.º 1
0
        private void BTN_Start_Click(object sender, EventArgs e)
        {
            BTN_Start.Enabled     = false;
            BTN_Exit.Enabled      = true;
            BTN_NewClient.Enabled = true;

            WorkerBarber.RunWorkerAsync();
        }
Exemplo n.º 2
0
        private void BTN_NewClient_Click(object sender, EventArgs e)
        {
            queue();

            if (WorkerBarber.IsBusy != true)
            {
                WorkerBarber.RunWorkerAsync();
            }
        }
Exemplo n.º 3
0
        private void BTN_Exit_Click(object sender, EventArgs e)
        {
            WorkerBarber.CancelAsync();
            WorkerQueue.CancelAsync();

            BTN_Start.Enabled     = true;
            BTN_Exit.Enabled      = false;
            BTN_NewClient.Enabled = false;
        }
Exemplo n.º 4
0
        private void barberStartWorking()
        {
            if (nClients > 0)
            {
                WorkerBarber.ReportProgress(1);
                dequeue();

                int haircutDuration = randomInt.Next(haircutMinDuration, haircutMaxDuration);
                Thread.Sleep(haircutDuration);
            }
            else
            {
                WorkerBarber.ReportProgress(0);
            }
        }
Exemplo n.º 5
0
        private void WorkerBarber_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            // 0 for Idle, 1 for Bussy
            int  workerState = e.ProgressPercentage;
            bool idle        = true;

            switch (workerState)
            {
            case 0: idle = true; WorkerBarber.CancelAsync(); break;

            case 1: idle = false; break;

            default: break;
            }

            changeBarberState(idle);
            updateVisualChairs(nClients);
        }