Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7944497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:34:10+00:00 2026-06-04T00:34:10+00:00

The variable ‘totalBytes’ is constantly at -1 so I cannot calculate/update the progress bar

  • 0

The variable ‘totalBytes’ is constantly at -1 so I cannot calculate/update the progress bar correctly, why would this be happening?

private void button1_Click(object sender, EventArgs e)
{
    WebClient client = new WebClient();
    client.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
    client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
    client.DownloadFileAsync(new Uri("http://example.com/test.mp3"), @"E:\Test.mp3");
}

private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
    double bytesIn = double.Parse(e.BytesReceived.ToString());
    label1.Text = Convert.ToString(bytesIn);

    double totalBytes = double.Parse(e.TotalBytesToReceive.ToString()); //stays at -1
    label2.Text = Convert.ToString(totalBytes);

    double percentage = bytesIn / totalBytes * 100;
    label3.Text = Convert.ToString(percentage);

    progressBar1.Value = int.Parse(Math.Truncate(percentage).ToString());
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T00:34:11+00:00Added an answer on June 4, 2026 at 12:34 am

    A WebClient uses a WebRequest internally, and the problem is likely that the server you are downloading the file from is not sending the Content-Length HTTP header, in which case you should use a Indeterminate ProgressBar style (eg. Marquee).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Before variable-length arrays were supported, I would dynamically allocate them like this: int foo(size_t
Possible Duplicate: C# member variable initialization; best practice? Is there any benefit to this:
This variable is defined in xyz.cpp const int i = 10; The below main()
$image variable gives this code (when echo is used): <img src=/image.png width=100 height=147 alt=
this variable will collect the html which will eventually be placed in the side_bar
JSTL variable values are not shown in EL. For example this code: <%@ taglib
Can variable be assigned self invoking function module so that the variable reference would
What variable is used for the database connection instance in WordPress? PS: I would
// Member Variable private static readonly object _syncLock = new object(); // Now inside
$alltext variable contents this code inside: <li>sometext</li><li>sometext</li> <li>sometext</li><li>sometext</li> How do I get each <li>...</li>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.