Ejemplo n.º 1
0
 private void StopButton_Click(object sender, EventArgs e)
 {
     try
     {
         StartButton.Enabled = true;
         StopButton.Enabled  = false;
         ThreadsManager.Stop();
     }
     catch (Exception ex)
     {
         MessageBox.Show(this, ex.ToString(), "Error: Can not stop execution.",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Ejemplo n.º 2
0
        private void ThreadsManager_Tick(object sender, EventArgs e)
        {
            while (ThreadsNumeric.Value > ExecutionWorkers.Count)
            {
                var worker = new BackgroundWorker();
                worker.DoWork             += ExecutionWorker_DoWork;
                worker.RunWorkerCompleted += ExecutionWorker_RunWorkerCompleted;
                ExecutionWorkers.Add(worker);
            }
            bool enquire_next = false;

            for (int i = 0; i < ExecutionWorkers.Count; i++)
            {
                var worker = ExecutionWorkers[i];
                if (worker.IsBusy)
                {
                    enquire_next = true;
                    continue;
                }
                if (ThreadsNumeric.Value < ExecutionWorkers.Count)
                {
                    ExecutionWorkers.RemoveAt(i--);
                }
                else if (SubmitWork(worker))
                {
                    enquire_next = true;
                }
            }
            if (GraphDirty)
            {
                BuildGraph();
            }

            if (!enquire_next)
            {
                StartButton.Enabled = true;
                StopButton.Enabled  = false;
                ThreadsManager.Stop();
            }
        }