-
progress bar update?
Hi there.
I would like to know exactly how to go about creating a progress bar showing the "transfer" complete progress?
Basically, my app connects to an FTP and downloads a file. Objects are created locally to identify what the file is, if its a directory, what the size is of the file and so on...
I know I have to create a thread for the progress bar to avoid the UI from "hanging".
I pretty much have a progress bar on the form, and have made a method/thread to "Do" the progress bar update.
The thread gets created/called when the file it about to be downloaded.
But now what? How do I make the progress bar show almost "truely" or in sync or whatever, how much of the file has been downloaded?
do I set the maximum property of the progress bar to the size of the file to be downloaded?
then what? :)
-
Re: progress bar update?
What is your code for downloading like? Is it something that updates at regular intervals, or a thread that is started and nothing happens until the file is finished?
Bill
-
Re: progress bar update?
:) don't worry about the code when downloading... i dont really think that has any "integration" with the progress ;) well it may do only when writing to a stream.....
im using .NET 2.0
im just using an FTP Request to download the file, it is then reading it and writing it to a BinaryReader/Writer stream
-
Re: progress bar update?
Well i hope someone can help
I pretty much did it my way - whilst it is reading the buffer, it writes to file and sets the step value to the buffer count.
cool, all works
now trying to find a way of finding the % so I can display that to the user, either using the progress value's properties (which will have the maximum value > 100) or some other calc...
-
Re: progress bar update?
Take a look at the two links I posted in this thread to see if they help you.
-
Re: progress bar update?
unfortunatly not :( I already had a look :)
code:
Code:
byte[] buffer = new byte[2048];
int count = theBinReader.Read(buffer, 0, buffer.Length);
this.SetStepProgValue(count);
this.DoStepProgValue();
while (count != 0)
{
theBinWriter.Write(buffer, 0, count);
count = theBinReader.Read(buffer, 0, buffer.Length);
this.SetStepProgValue(count);
this.DoStepProgValue();
}
-
Re: progress bar update?
done!
calculate_percent = count * 100 / theFileSize
where count = the stream reader read