private void OnButtonClick(object sender, ToolStripItemClickedEventArgs e)
 {
     if (e.ClickedItem == StopButton)
     {
         StopButton.Checked  = true;
         StopButton.Enabled  = false;
         PauseButton.Checked = false;
         PauseButton.Enabled = false;
         _JobRunner.Stop();
         Timer1.Enabled = false;
         PerformanceSeries.Clear();
         ShowDetailButton.Visible = true;
     }
     else if (e.ClickedItem == PauseButton)
     {
         PauseButton.Checked = !PauseButton.Checked;
         if (PauseButton.Checked)
         {
             _JobRunner.Pause();
         }
         else
         {
             _JobRunner.Resume();
         }
     }
 }
        private void OnTimerTick(object sender, EventArgs e)
        {
            try
            {
                Total.Text        = _JobRunner.Jobs.Count.ToString();
                ProgressBar.Value = _JobRunner.PercentageComplete;

                int NumCompleted;
                int NumWithErrors;
                int NumWithWarnings;
                _JobRunner.CalcStats(out NumCompleted, out NumWithErrors, out NumWithWarnings);
                Completed.Text          = NumCompleted.ToString();
                NumberWithErrors.Text   = NumWithErrors.ToString();
                NumberWithWarnings.Text = NumWithWarnings.ToString();

                if (ProgressBar.Value >= 100 && !this.Text.Contains("100% complete"))
                {
                    string WavFileName = Configuration.Instance.Setting("ApsimFinishedWAVFileName");
                    if (File.Exists(WavFileName))
                    {
                        System.Media.SoundPlayer Player = new System.Media.SoundPlayer(WavFileName);
                        Player.Play();
                    }
                    ShowDetailButton.Visible = true;
                    Timer1.Enabled           = false;
                    PerformanceSeries.Clear();
                    if (AutoClose)
                    {
                        // pause for 5 sec to make sure Windows has finished writing everything to stdout.
                        Thread.Sleep(5000);
                        Close();
                    }
                }
                this.Text = ProgressBar.Value.ToString() + "% complete";
                if (PauseButton.Checked)
                {
                    this.Text += " - Paused";
                }
                if (StopButton.Checked)
                {
                    this.Text += " - Aborted";
                }

                if (PerformanceCounter != null)
                {
                    Array.Copy(values, 1, values, 0, 9);
                    values[9] = PerformanceCounter.NextValue();
                    PerformanceSeries.Clear();
                    PerformanceSeries.Add(values);
                }
            }
            catch
            {
            }
        }