Exemple #1
0
        /// <summary>
        /// Monitors progress of an operation executing asynchronously in
        /// another thread.
        /// The supplied callback is used to determine the completion progress
        /// of the operation, and whether or not it is still running.
        /// This method blocks until the callback sets the isRunning parameter
        /// to false, or the IOutput instance indicates the operation should be
        /// cancelled, e.g. because the user hits the Escape key.
        /// For a non-blocking alternative, use MonitorProgressAsync.
        /// </summary>
        public void MonitorProgress(GetProgress progressFn)
        {
            int progress = 0;
            DateTime lastPoll = DateTime.MinValue;
            bool cancel = false;
            bool cancelNotified = false;
            bool isRunning = true;

            do {
                // Sleep for half a second
                // Note: the initial delay before displaying a progress bar the first time is deliberate
                // It allows time for the task thread to log messages as it starts it's work
                Thread.Sleep(SLEEP_INTERVAL);

                // Determine progress
                if (lastPoll == null || DateTime.Now.AddSeconds(-PollingInterval) > lastPoll) {
                    progress = progressFn(cancel, out isRunning);
                    cancelNotified = cancelNotified || cancel;
                    lastPoll = DateTime.Now;
                }

                // Update progress status
                cancel = _output.SetProgress(progress);
            }
            while(isRunning && !cancelNotified);

            _output.IterationComplete();

            if(cancel) {
                _log.Info("Operation cancelled");
            }
        }
Exemple #2
0
        /// <summary>
        /// Monitors progress of an operation executing asynchronously in
        /// another thread.
        /// The supplied callback is used to determine the completion progress
        /// of the operation, and whether or not it is still running.
        /// This method blocks until the callback sets the isRunning parameter
        /// to false, or the IOutput instance indicates the operation should be
        /// cancelled, e.g. because the user hits the Escape key.
        /// For a non-blocking alternative, use MonitorProgressAsync.
        /// </summary>
        public void MonitorProgress(GetProgress progressFn)
        {
            int      progress       = 0;
            DateTime lastPoll       = DateTime.MinValue;
            bool     cancel         = false;
            bool     cancelNotified = false;
            bool     isRunning      = true;

            do
            {
                // Sleep for half a second
                // Note: the initial delay before displaying a progress bar the first time is deliberate
                // It allows time for the task thread to log messages as it starts it's work
                Thread.Sleep(SLEEP_INTERVAL);

                // Determine progress
                if (lastPoll == null || DateTime.Now.AddSeconds(-PollingInterval) > lastPoll)
                {
                    progress       = progressFn(cancel, out isRunning);
                    cancelNotified = cancelNotified || cancel;
                    lastPoll       = DateTime.Now;
                }

                // Update progress status
                cancel = _output.SetProgress(progress);
            }while(isRunning && !cancelNotified);

            _output.IterationComplete();

            if (cancel)
            {
                _log.Info("Operation cancelled");
            }
        }
Exemple #3
0
        public MenuProgressBar(Vector2i componentSize, FloatRect backdropBounds, FloatRect barBounds, GetProgress barProgress, Color barColor)
        {
            Initialize(componentSize);

            backdrop         = CreateMenuGraphic(backdropBounds, componentSize);
            bar              = CreateMenuGraphic(barBounds, componentSize, barColor);
            this.barProgress = barProgress;
        }
Exemple #4
0
 /// <summary>
 /// Monitors progress of a synchronously executing (i.e. blocking)
 /// operation.
 /// This method spins up a background thread to poll the operation
 /// status, and so it returns immediately. Use this method when you want
 /// to monitor the progress of a long-running, blocking operation. Be
 /// sure to call this method immediately prior to invoking the operation.
 /// </summary>
 public void MonitorProgressAsync(GetProgress progressFn)
 {
     _monitorThread = new System.Threading.Thread(() => {
         _log.Trace("Starting progress monitor thread");
         MonitorProgress(progressFn);
         _log.Trace("Progress monitor thread finished");
     });
     _monitorThread.Start();
 }
Exemple #5
0
 /// <summary>
 /// Monitors progress of a synchronously executing (i.e. blocking)
 /// operation.
 /// This method spins up a background thread to poll the operation
 /// status, and so it returns immediately. Use this method when you want
 /// to monitor the progress of a long-running, blocking operation. Be
 /// sure to call this method immediately prior to invoking the operation.
 /// </summary>
 public void MonitorProgressAsync(GetProgress progressFn)
 {
     _monitorThread = new System.Threading.Thread(() => {
         _log.Trace("Starting progress monitor thread");
         MonitorProgress(progressFn);
         _log.Trace("Progress monitor thread finished");
     });
     _monitorThread.Start();
 }
Exemple #6
0
 public void SetProgress(float progress)
 {
     _getTotalProgressFunc = null;
     UpdateProgress(progress);
 }