Пример #1
0
        /// <summary>
        /// Private.
        ///
        /// The progress reporting function. Pushes progress reports out at a predefined interval.
        /// (Note continous updates cause a backlog in the UI, so this is avoided.)
        /// </summary>
        /// <returns>true to indicate continuation, false to indicate the user has requested
        /// the operation be cancelled. Unless DisableThrowOnCancel has been called the result
        /// will always be true and a TaskCanceledException will be thrown to instead indicate
        /// cancellation.</returns>
        private bool ReportProgress()
        {
            if (_lastUpdate.ElapsedMilliseconds > MAX_UPDATE_TIME || _forceUpdate)
            {
                // Update!

                // Get text
                string text = StringHelper.ArrayToString(_texts.Reverse(), " – ");

                // Get continue text
                string ctext;

                if (_continue != null)
                {
                    ctext = _continue;
                }
                else if (_bytes != 0)
                {
                    ctext = StringHelper.DisplayBytes(_bytes);
                }
                else
                {
                    ctext = null;
                }

                _destination.ReportProgressDetails(new ProgInfo(text, _percent, ctext));

                _lastUpdate.Restart();
                _forceUpdate = false;
            }

            if (!_allowContinue && (_throwOnCancel == 0))
            {
                throw new TaskCanceledException("The task was cancelled.");
            }

            return(_allowContinue);
        }