Exemplo n.º 1
0
 /// <summary>
 /// Raises the ProgressChange event.
 /// </summary>
 /// <param name="e">An event args that contains the event data.</param>
 protected virtual void OnProgressChange(BrowserProgressChangeEventArgs e)
 {
     if (ProgressChange != null)
     {
         ProgressChange(this, e);
     }
 }
 /// <summary>
 /// Raises the ProgressChange event.
 /// </summary>
 /// <param name="e">An event args that contains the event data.</param>
 protected virtual void OnProgressChange(BrowserProgressChangeEventArgs e)
 {
     if (ProgressChange != null)
         ProgressChange(this, e);
 }
        /// <summary>
        /// Handle progress changed event
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">event args</param>
        private void browserControl_ProgressChange(object sender, BrowserProgressChangeEventArgs e)
        {
            if (progressHost.CancelRequested)
                throw new OperationCancelledException();

            long longMax = e.ProgressMax;
            long longComp = e.Progress;
            int intMax = (int)longMax;
            int intComp = (int)longComp;

            // Unfortunately, either Max or Completed can be greater, due to IE bug.
            // Make sure the bigger one is no bigger than int.MaxValue.
            while (longMax > int.MaxValue || longComp > int.MaxValue)
            {
                if (longMax > longComp)
                {
                    intMax = int.MaxValue;
                    intComp = (int)(((double)longComp / longMax) * intMax);
                }
                else
                {
                    intComp = int.MaxValue;
                    intMax = (int)(((double)longMax / longComp) * intComp);
                }
            }

            // Don't allow progress to exceed 100%
            if (intComp > intMax)
                intComp = intMax;

            progressHost.UpdateProgress(intComp, intMax, string.Format(CultureInfo.CurrentCulture, Res.Get(StringId.ProgressDownloading), ProgressName));
        }