13,041,923 members (64,507 online)
Rate this:
See more: (untagged)
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();<br />`

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 22:16pm

Rate this:

## 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
v2
StephenTan 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 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 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 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

Top Experts
Last 24hrsThis month
 OriginalGriff 125 Karthik Bangalore 105 ppolymorphe 105 Satya Prakash Swain 71 gaurav.s23 70
 OriginalGriff 4,205 RickZeeland 1,834 ppolymorphe 1,454 F-ES Sitecore 1,448 Dave Kreskowiak 1,299