views:

214

answers:

1

Hello everyone,

I am using VSTS 2008 + C# + .Net 3.5 to develop a console application to upload a file to server. I want to show upload progress. I want to use WebClient.UploadProgressChanged Event, but confused about its function -- "Occurs when an asynchronous upload operation successfully transfers some or all of the data." My confusion is, when this event will be raised? The word "some or all" is too confusing, does it mean this event will be called each time 1% of file is upload? 10%? Some fixed bytes? Called randomly? Or something else?

http://msdn.microsoft.com/en-us/library/system.net.webclient.uploadprogresschanged.aspx

thanks in advance, George

+1  A: 

It does kind of what it says. Expect many calls to the event for a big file and only 1 or 2 for a small page. The UploadProgressChangedEventArgs contains the relevant information.

Henk Holterman
My confusion is what is the rule how often this method is called? Once per 1%? Being called when transfer some fixed number of bytes? Or being called purely random and can not estimate (e.g. even we transfer the same file, may be the 1st time upload 5 times progress change reported, the 2nd time upload 10 times progress reported)? Appreciate if you could random?
George2
IF I could random? I'll try. I expect that it is implemented opportunistically, it wouldn't be worth it to do any accurate or round number based reporting. So take it as it comes. Why do you consider this so important?
Henk Holterman
I am implementing a progress bar for file upload. If this progress report callback will only be called rarely, it will break user experience (e.g. if user upload a file which takes an hour, if this event reporter only be called twice, the user will only have two status, 50% completed and 100% completed). I want to have a good granularity. If this function is not good enough, I have to implement my own. Any ideas?
George2
A Progressbar in a Console application?
Henk Holterman
I am sorry. For Forms application. My typo and since I am developing console application in 90% cases. :-)Any advice for progress bar development issue I mentioned above?
George2
Any advice? Yes, just plug the procentComplete value into the Progressbar and don't worry. The whole thing was designed to give a (reasonable) feedback.
Henk Holterman
Thanks for your advice, Henk! The final question, seems no public document mentions the rule when the progress changed event will be raised?
George2
George2, I don't know such document.
Henk Holterman
Thanks Henk, question answered!
George2