HI Ferdinand,

Thank you for the hint. I'll try the 2nd one :-) Multi-threading sounds cool.

Best regards,
Viet.

On Fri, Oct 24, 2008 at 12:05 AM, Ferdinand Beyer <fb@fbeyer.com> wrote:
Am 23.10.2008 um 12:20 schrieb Viet Le:

Hi all,

I'm thinking of tracking progress when uploading/downloading files to/from the web/FTP server. Uploading and downloading can be done with HTMLForm and HTTPRequest & HTTPResponse. However, how to track the progress of uploading & downloading? If you have any idea, please share. Thank you in advance!

Best regards,
Viet.

Viet,

Tracking progress can be done by tracking how many bytes have been transferred relative to the total number of bytes (ie. the size of the file). If you use the StreamCopier to write data to your output stream (like the one returned from HTTPClientSession), you cannot track progress since it blocks until all data is written.

You can implement progress tracking in many ways. One possibility is to replace the usage of StreamCopier with a loop writing the data in chunks and track the number of bytes written in a variable. You can either report the progress here from your main thread or use a different thread for progress reporting. The latter solution is more elegant but also much more complicated since you will have to deal with concurrency problems (Mutex and friends).

Best regards,
Ferdinand

-- 
Ferdinand Beyer






--
I submit to you that if a man hasn't discovered something he will die for, he isn't fit to live.
(Martin Luther King Jr.)
-----