Click here to Skip to main content
11,920,377 members (57,949 online)
Rate this:
Please Sign up or sign in to vote.
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();

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
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);

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.
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.

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

  Print Answers RSS
0 OriginalGriff 415
1 phil.o 170
2 Dave Kreskowiak 155
4 F-ES Sitecore 130
0 OriginalGriff 6,778
1 KrunalRohit 4,495
2 Sergey Alexandrovich Kryukov 3,203
3 George Jonsson 2,805
4 Suvendu Shekhar Giri 2,181

Advertise | Privacy | Mobile
Web02 | 2.8.151120.1 | Last Updated 30 May 2011
Copyright © CodeProject, 1999-2015
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