cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements
Update: Find information on Dropbox support during COVID-19 here
Close
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted

How to display Progress Status while uploading/ downloading a file ( in .Net ) ?

New member | Level 1
New member | Level 1

I have tried with downloading and uploading functions, it gives the progress data alright, but I can not set that data to progress bar. I have worked with couple of hours but can not place that process status in the progress bar or any other way. I have attached codes of Upload 

 

private async Task ChunkUpload()
{

string path = UploadFolder + "/" + UploadFile;
FileStream stream = UploadFileStream;
int chunkSize = 128 * 1024;

DropboxClient dbx = new DropboxClient(SystemVariables.WebAcccessToken);
int numChunks = (int)Math.Ceiling((double)stream.Length / chunkSize);
byte[] buffer = new byte[chunkSize];
string sessionId = null;



for (var idx = 0; idx < numChunks; idx++)
{


var byteRead = stream.Read(buffer, 0, chunkSize);

using (var memSream = new MemoryStream(buffer, 0, byteRead))
{
if (idx == 0)
{
var result = await dbx.Files.UploadSessionStartAsync(false, memSream);
sessionId = result.SessionId;
}
else
{
var cursor = new UploadSessionCursor(sessionId, (ulong)(chunkSize * idx));
var percentage = 100 * ((chunkSize * idx) / (double)stream.Length);
pValue = (int)Math.Ceiling((decimal)percentage);



// Approach 1

var progressIndicator = new Progress<int>(ReportProgress);
int uploads = await UploadProgress(progressIndicator);


// Approach 2

/*
Thread t = new Thread(new ThreadStart(this.DoProcess));

t.Start();

while (t.IsAlive) // while thread is running
{

Application.DoEvents(); // Allow UI to refresh if needed

Thread.Sleep(10000); // sleep a while to avoid processor load
t.Abort();
}*/


if (idx == numChunks - 1)
{
await dbx.Files.UploadSessionFinishAsync(cursor, new CommitInfo(path), memSream);
}
else
{
await dbx.Files.UploadSessionAppendV2Async(cursor,false, memSream);

}
}
}
}
}





public delegate void UpdateProgressBarDelegate(int progress);
public UpdateProgressBarDelegate UpdateProgressBar;

private void UpdateProgressBarMethod(int progress)
{
IAsyncResult result = this.progressBar1.BeginInvoke(
(MethodInvoker)delegate()
{
progressBar1.Value = progress;
Text = progress.ToString();
//txtLogDetails.Text = message;

});
}

private void DoProcess()
{
UpdateProgressBarMethod(pValue);
}






void ReportProgress(int value)
{
progressBar1.Value = value;
}

async Task<int> UploadProgress(IProgress<int> progress)
{
int processCount = await Task.Run<int>(() =>
{
if (progress != null)
{
progress.Report(pValue);
}

return pValue;
});
return processCount;
}



You can see the 2 approaches that I have tried to update progress bar value,
but can not see the update in progress bar.

It will be great if you provide the detail code for display updates in progress bar from the scrat
1 Reply 1
Highlighted

Re: How to display Progress Status while uploading/ downloading a file ( in .Net ) ?

Dropboxer
Dropboxer

This looks like a continuation of your question from your other thread. As I mentioned there, this part isn't about Dropbox, so I can't offer any help. Also, this probably isn't the best forum for getting help for questions like this. You may want to try StackOverflow, or a forum for .NET.

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?