public TimeSpan getIntervalFromVerbosity()
        {
            /* this is a very subjective little function. Basically, we want to
             * update the searchProcessController more often for high verbosity
             * systems. The time it returns is in tenths-of-a-microsecond, and
             * so 10,000 corresponds to an update every millisecond and 10,000,000
             * is a second. */
            switch (SearchIO.getVerbosity(searchThread.ManagedThreadId))
            {
            case 0:
                return(new TimeSpan(25000000));

            case 1:
                return(new TimeSpan(10000000));

            case 2:
                return(new TimeSpan(5000000));

            case 3:
                return(new TimeSpan(1000000));

            case 4:
                return(new TimeSpan(500000));
            }
            return(new TimeSpan(500000));
        }
        public int getIntervalFromVerbosity()
        {
            /* this is a very subjective little function. Basically, we want to
             * update the searchProcessController more often for high verbosity
             * systems. The time it returns is in milliseconds, and so 2 corresponds
             * to an update once a second (1000 milliseconds). */
            switch (SearchIO.getVerbosity(searchThread.Name))
            {
            case 0: return(2500);

            case 1: return(1000);

            case 2: return(500);

            case 3: return(100);

            case 4: return(50);
            }
            return(500);
        }
        public void updateSPCDisplay(object sender, EventArgs e)
        {
            ThreadState currentState = searchThread.ThreadState;

            /* the ugly truth is that the threadState can change during the following
             * conditions. To avoid problems we set up a local variable first. */
            iterationBox.Text = SearchIO.getIteration(searchThread.Name).ToString();
            miscBox.Text      = SearchIO.getMiscObject(searchThread.Name);
            verbosityComboBox.SelectedIndex = SearchIO.getVerbosity(searchThread.Name);
            processTimer.Interval           = getIntervalFromVerbosity();
            try { priorityComboBox.SelectedIndex = (int)searchThread.Priority; }
            catch { }
            if ((currentState == ThreadState.AbortRequested) ||
                (currentState == ThreadState.StopRequested) ||
                (currentState == ThreadState.SuspendRequested))
            {
                this.playButton.Enabled        = false;
                this.pauseButton.Enabled       = false;
                this.stopButton.Enabled        = false;
                this.abortButton.Enabled       = true;
                this.ControlBox                = false;
                this.priorityComboBox.Enabled  = true;
                this.verbosityComboBox.Enabled = true;
                updateTimeDisplay();
            }
            else if (currentState == ThreadState.Suspended)
            {
                this.playButton.Enabled        = true;
                this.pauseButton.Enabled       = false;
                this.stopButton.Enabled        = false;
                this.abortButton.Enabled       = true;
                this.ControlBox                = false;
                this.priorityComboBox.Enabled  = true;
                this.verbosityComboBox.Enabled = true;
            }
            else if ((currentState == ThreadState.Running) ||
                     (currentState == ThreadState.WaitSleepJoin))
            {
                this.playButton.Enabled        = false;
                this.pauseButton.Enabled       = true;
                this.stopButton.Enabled        = true;
                this.abortButton.Enabled       = true;
                this.ControlBox                = false;
                this.priorityComboBox.Enabled  = true;
                this.verbosityComboBox.Enabled = true;
                updateTimeDisplay();
            }
            else if ((currentState == ThreadState.Stopped) ||
                     (currentState == ThreadState.Aborted))
            {
                if (abortedTime != 0)
                {
                    long test = DateTime.Now.Ticks - abortedTime;
                    if (test > 50000000)
                    /* after 5 seconds(?) close the search process window */
                    {
                        this.processTimer.Stop();
                        this.Close();
                    }
                }
                else
                {
                    this.playButton.Enabled        = false;
                    this.pauseButton.Enabled       = false;
                    this.stopButton.Enabled        = false;
                    this.abortButton.Enabled       = false;
                    this.ControlBox                = true;
                    this.priorityComboBox.Enabled  = false;
                    this.verbosityComboBox.Enabled = false;
                    abortedTime = DateTime.Now.Ticks;
                }
            }
        }
        public void updateSPCDisplay(object sender, EventArgs e)
        {
            try
            {
                var currentState = searchThread.ThreadState;

                /* the ugly truth is that the threadState can change during the following
                 * conditions. To avoid problems we set up a local variable first. */
                lblIterationBox.Content    = SearchIO.getIteration(searchThread.ManagedThreadId).ToString();
                lblMiscBox.Content         = SearchIO.getMiscObject(searchThread.ManagedThreadId);
                cmbVerbosity.SelectedIndex = SearchIO.getVerbosity(searchThread.ManagedThreadId);
                processTimer.Interval      = getIntervalFromVerbosity();
                try
                {
                    cmbPriority.SelectedIndex = (int)searchThread.Priority;
                }
                catch
                {
                }
                switch (currentState)
                {
                case ThreadState.SuspendRequested:
                case ThreadState.StopRequested:
                case ThreadState.AbortRequested:
                    btnPlay.IsEnabled      = false;
                    btnPause.IsEnabled     = false;
                    btnStop.IsEnabled      = false;
                    btnAbort.IsEnabled     = true;
                    cmbPriority.IsEnabled  = true;
                    cmbVerbosity.IsEnabled = true;
                    updateTimeDisplay();
                    break;

                case ThreadState.Suspended:
                    btnPlay.IsEnabled      = true;
                    btnPause.IsEnabled     = false;
                    btnStop.IsEnabled      = false;
                    btnAbort.IsEnabled     = true;
                    cmbPriority.IsEnabled  = true;
                    cmbVerbosity.IsEnabled = true;
                    break;

                case ThreadState.WaitSleepJoin:
                case ThreadState.Running:
                    btnPlay.IsEnabled      = false;
                    btnPause.IsEnabled     = true;
                    btnStop.IsEnabled      = true;
                    btnAbort.IsEnabled     = true;
                    cmbPriority.IsEnabled  = true;
                    cmbVerbosity.IsEnabled = true;
                    updateTimeDisplay();
                    break;

                case ThreadState.Aborted:
                case ThreadState.Stopped:
                    if (abortedTime != 0)
                    {
                        var test = DateTime.Now.Ticks - abortedTime;
                        if (test > 50000000)
                        /* after 5 seconds(?) close the search process window */
                        {
                            processTimer.Stop();
                            Close();
                        }
                    }
                    else
                    {
                        btnPlay.IsEnabled  = false;
                        btnPause.IsEnabled = false;
                        btnStop.IsEnabled  = false;
                        btnAbort.IsEnabled = false;
                        //  this.ControlBox = true;
                        cmbPriority.IsEnabled  = false;
                        cmbVerbosity.IsEnabled = false;
                        abortedTime            = DateTime.Now.Ticks;
                    }
                    break;
                }
            }
            catch (Exception exc)
            {
                ErrorLogger.Catch(exc);
            }
        }