Exemple #1
0
        /// <summary>
        ///     Updates the progress bar based on the position in the task sequence.
        /// </summary>
        private void ProgressBarRefresh()
        {
            // Get position in task sequence if there is one
            int currentInstruction;
            int lastInstruction;

            try
            {
#if DEBUG
                currentInstruction = 50;
                lastInstruction    = 100;
#else
// Get the current position in the task sequence - will get blanks and exceptions if not in a TS
                currentInstruction = int.Parse(TaskSequence.GetVariable("_SMSTSNextInstructionPointer")) + 1;
                lastInstruction    = int.Parse(TaskSequence.GetVariable("_SMSTSInstructionTableSize")) + 1;
#endif

                if (currentInstruction > lastInstruction)
                {
                    currentInstruction = lastInstruction;
                }
            }
            catch (Exception)
            {
                // Error reading task sequence variables, remove progress bar
                progressBar.Visible = false;

                // Have we been running in a task sequence before? If so, assume that the task sequence has ended
                // and close down - this prevents situations where the caller forgets to close us at the end of a TS
                if (_startedInTaskSequence)
                {
                    _eventShutdownRequested.Set();
                }

                return;
            }

            // If we reached here, we are in a task sequence, update flag
            _startedInTaskSequence = true;

            // If bar is not enabled then nothing else to do
            if (!_progressBarEnabled)
            {
                progressBar.Visible = false;
                return;
            }

            // Set percentage and make visible
            progressBar.Value   = 100 * currentInstruction / lastInstruction;
            progressBar.Visible = true;
        }