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 7597847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:15:32+00:00 2026-05-30T22:15:32+00:00

I know progress bars by themselves have been already asked to death, but I’m

  • 0

I know progress bars by themselves have been already asked to death, but I’m having trouble with one. I need to download a file via FTP, I’m using WebClient, the downloaded data has to be saved to a byte array, but WebClient.DownloadDataAsync can’t return it directly, so I have to use the DownloadDataCompleted method to acces the data. Everything up till there is ok, but the problem is that I can’t “pause” the IEnumerator block without blocking the whole thread, and if I don’t pause it, the app crashes because the byte array doesn’t exist when it tries to access it. When the file to download was in http I used WWW and had no problems, but it had to be moved to FTP. Using WebClient.DownloadData works, but I was asked to include a progress bar. Anyway, here´s the code:

    IEnumerator DownloadGame(Dictionary<string, string> settingsDict)
    {
       statusText = "Starting download...";
       WebClient request = new WebClient();
       request.Credentials = new NetworkCredential("user", "password");
       request.DownloadDataCompleted += DownloadDataCompleted;

      //byte[] fileData = request.DownloadData(settingsDict["downloadlink"]); This works, but is no good since it blocks the thread
    request.DownloadDataAsync(new Uri(settingsDict["downloadlink"]),"somefilepath");


    //do{}while(!downloadFinished); This also works but blocks the thread anyway


    //Process the update
    string tmpRoot = TMPFolder();
    string tmpFolder = tmpRoot + Application.platform + settingsDict["latestVersion"] + "/";
    if (!UnzipUpdate(fileData, tmpFolder))//fail here, in this case fileData is global
    {
        DeleteDirectory(tmpRoot); 
        yield break;
    }
    if (!ProcessUpdateData(tmpFolder))
    {
        DeleteDirectory(tmpRoot); 
        yield break;
    }
    DeleteDirectory(tmpRoot);

    settingsDict["thisVersion"] = GetNextVersion();
}

 void DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e){

   fileData = e.Result;
   downloadFinished = true;
 }
  • 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-05-30T22:15:33+00:00Added an answer on May 30, 2026 at 10:15 pm

    you can use something like this based on a previous Stakoverflow post..

    The easiest is to use BackgroundWorker and put your code into DoWork event handler. And report progress with BackgroundWorker.ReportProgress.

    The basic idea:

    private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
    {
        var ftpWebRequest = (FtpWebRequest)WebRequest.Create("ftp://xxx.com");
        ftpWebRequest.Method = WebRequestMethods.Ftp.UploadFile; //or DownLoad
        using (var inputStream = File.OpenRead(fileName))
        using (var outputStream = ftpWebRequest.GetRequestStream())
        {
            var buffer = new byte[1024 * 1024];
            int totalReadBytesCount = 0;
            int readBytesCount;
            while ((readBytesCount = inputStream.Read(buffer, 0, buffer.Length)) > 0)
            {
                outputStream.Write(buffer, 0, readBytesCount);
                totalReadBytesCount += readBytesCount;
                var progress = totalReadBytesCount * 100.0 / inputStream.Length;
                backgroundWorker1.ReportProgress((int)progress);
            }
        }
    }
    
    private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
    {
        progressBar.Value = e.ProgressPercentage;
    }
    

    Make sure WorkerReportsProgress is enabled

    backgroundWorker2.WorkerReportsProgress = true;
    

    With BackgroundWorker you can also easily implement upload cancellation.

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

Sidebar

Related Questions

Know this might be rather basic, but I been trying to figure out how
I know this is a rookie question but whats actually happening with a progress
I know how to use handlers to update UI elements such as progress bars
I am doing stuff with ajax progress bars and stuff... Basically I have a
In html and jQuery, how do you show multiple horizontal progress bars? I have
I know this question has been asked several times an I spent all day
Anyone know a way to disable Bootstrap's CSS3 transitions on the progress bars? I'm
hey guys, i know there are a lot of for-me-too-complicated versions of progress-bars for
Does anyone know of any methods to create a file upload progress bar in
I know that the following code should show and hide a tiny circular progress

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.