Beispiel #1
0
        public void UpdateProgress(DownloadProgressChangedEventArgs e)
        {
            if (progressBar.InvokeRequired)
            {
                UpdateProgressDelegate _delegate = new UpdateProgressDelegate(UpdateProgress);
                progressBar.Invoke(_delegate, new object[] { e });
            }
            else
            {
                double mult = 1.0;
                if (TotalUpdateSize > int.MaxValue)
                {
                    mult = (double)int.MaxValue / TotalUpdateSize;
                }

                progressBar.Minimum = 0;
                progressBar.Maximum = (int)(TotalUpdateSize * mult);

                // Set the current value.  In certain circumstances, this value may
                // become invalid, so we need to test it first.
                // NOTE: Fixes bug #1770765 - Status Bar Exception
                int currValue = (int)((CompletedUpdateSize + e.BytesReceived) * mult);
                if (currValue >= progressBar.Minimum &&
                    currValue <= progressBar.Maximum)
                {
                    progressBar.Value = currValue;
                }

                TimeSpan ts = (DateTime.Now - StartTime);

                lblBytes.Text =
                    DownloadedBytesStringConverter.Convert(CompletedUpdateSize + e.BytesReceived, TotalUpdateSize) +
                    " out of " +
                    DownloadedBytesStringConverter.Convert(TotalUpdateSize) +
                    " downloaded (" +
                    DownloadedBytesStringConverter.Convert(
                        (CompletedUpdateSize + e.BytesReceived) / ts.TotalSeconds,
                        "0.0") +
                    "/sec)";
            }
        }
        public void UpdateProgress(DownloadProgressChangedEventArgs e)
        {
            if (Thread.CurrentThread != Dispatcher.Thread)
            {
                UpdateProgressDelegate _delegate = new UpdateProgressDelegate(UpdateProgress);
                Dispatcher.Invoke(DispatcherPriority.Normal, _delegate, e);
            }
            else
            {
                double mult = 1.0;
                if (TotalUpdateSize > int.MaxValue)
                {
                    mult = (double)int.MaxValue / TotalUpdateSize;
                }

                progressBar.Minimum = 0;
                progressBar.Maximum = (TotalUpdateSize * mult);

                // Set the current value.  In certain circumstances, this value may
                // become invalid, so we need to test it first.
                // NOTE: Fixes bug #1770765 - Status Bar Exception
                double currValue = (CompletedUpdateSize + e.BytesReceived) * mult;
                if (currValue >= progressBar.Minimum &&
                    currValue <= progressBar.Maximum)
                {
                    progressBar.Value = currValue;
                }

                TimeSpan ts = (DateTime.Now - StartTime);

                SetParagraphText(
                    DownloadedBytesStringConverter.Convert(CompletedUpdateSize + e.BytesReceived, TotalUpdateSize) +
                    " out of " +
                    DownloadedBytesStringConverter.Convert(TotalUpdateSize) +
                    " downloaded");

                lblSpeed.Text = DownloadedBytesStringConverter.Convert(
                    (CompletedUpdateSize + e.BytesReceived) / ts.TotalSeconds,
                    "0.0") + "/sec";
            }
        }