Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: progress
Hi everyone!
Could someone please guide me in this problem?
 
I have a webservice that returns a byte array as follows:
 
byte[] BAReturn = myWebService.GetData();

 
The returned data is about 100MB.
I'm supposed to do a progressbar that tracks the percentage of completion of the transfer of the byte array stream. So what I did was to create a timer and insider the timer, the code is
 
myProgressBar.Percent = (BAReturn.Length / SizeOfData) * 100;
 
where SizeOfData is the known size of the byte array data to be transfered.
 
Now the problem is that it always just goes to 100 immediately no matter how big the data is. Just that there is a long pause before the sudden change to 100. This means i can't use BAReturn.Length to track the transfer.
 
How can i go about tracking the progress of transfer?
Thanks a million!!!!
Posted 29-May-11 23:16pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I think your problem in integer division and thus rounding error.
 
This would do much better:
 
// myProgressBar.Percent ...
myProgressBar.Value = (100 * BAReturn.Length) /SizeOfData;
 
To be completely sure, you can even do this:
 
double percent = (100d * BAReturn.Length) /SizeOfData;
myProgressBar.Value = (int)System.Math.Round(percent);
 

—SA
  Permalink  
v2
Comments
StephenTan at 30-May-11 4:58am
   
Thank you for your reply. The progressbar is not really the question, but to track the progress of the large return data from a function.
SAKryukov at 30-May-11 15:07pm
   
I answered to the question as you formulated it.
If you have something which is "really the question", consider asking it and get straight to the point.
Did my fix work for you? If so, please formally accept it (green button) and let's go ahead.
--SA
StephenTan at 30-May-11 21:12pm
   
Actually I'm not sure about the mechanism behind the function return of such a big data. It could be just returning an address after the whole data has been received, hence the sudden change to 100%. It has nothing to do with the rounding off.
SAKryukov at 30-May-11 23:08pm
   
What, not sure?! There is nothing to be sure about. Number of bytes number of bytes, nothing else. If you calculate it correctly. As do %, what you have written is just a bug.
Again, if you have a different concern, ask a different question.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 30 May 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100