Pop UP Progress Bar REPOST

  • Thread starter Thread starter Dino M. Buljubasic
  • Start date Start date
D

Dino M. Buljubasic

I am trying to create a pop up progress bar (on a form) that would show
progress from downloading files from an FTP server.

any help will be appreciated
 
I am trying to create a pop up progress bar (on a form) that would show
progress from downloading files from an FTP server.

any help will be appreciated

Put the FTP transfer in a different thread and have it raise events as
it downloads (perhaps raise an event every 8k downloaded). Have your
main form subscribe to this event and update your progress bar.

The key thing here is that the UI update has to be done on the main
thread (the one started by the runtime) since Windows Forms controls are
not thread-safe.
 
Dino M. Buljubasic said:
I am trying to create a pop up progress bar (on a form) that would
show progress from downloading files from an FTP server.

any help will be appreciated

Which question do you have? How to download the file? How to show the
progress bar?
 
Hi Patrick,

I'm fairly new to threading, but I had the impression that events couldn't
(or weren't supposed to) be used between threads -- that only Invoke and
BeginInvoke should be used to pass messages between threads. There's a
discussion of UI/worker threading issues in this article, with sample code
that uses Invoke and BeginInvoke as a clunky workaround:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadvnet/html/vbnet09272002.asp

Am I wrong -- can events safely be used instead?

--Robert Jacobson
 
I don't know how to show progress bar. Actaully, I am showing it now but it
does not refresh.

I have a separate form that holds progress bar. My progress bar is updated
inside a separate thread but only what I manage to update is the forms
title. Any controls inside the form such as the progress bar or labels
displaying name of the file being downloaded, are not refreshed.
 
OK, I understand that. Only one more thing, how to make it reaise event
when it has downloaded 8 or so kb?

I have a sub DownloadFile that downloades file from FTP server, but don't
know how to check for the number of bytes downloaded and then reaise event
while it downloads the bytes.

Thank you for your help
 
Why don't you use a UserControl, where you'll have the progress bar along
with other label or text.....




Dino M. Buljubasic said:
I don't know how to show progress bar. Actaully, I am showing it now but it
does not refresh.

I have a separate form that holds progress bar. My progress bar is updated
inside a separate thread but only what I manage to update is the forms
title. Any controls inside the form such as the progress bar or labels
displaying name of the file being downloaded, are not refreshed.
 
I'm fairly new to threading, but I had the impression that events couldn't
(or weren't supposed to) be used between threads -- that only Invoke and
BeginInvoke should be used to pass messages between threads. There's a
discussion of UI/worker threading issues in this article, with sample code
that uses Invoke and BeginInvoke as a clunky workaround:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadvnet/html/vbnet09272002.asp

Am I wrong -- can events safely be used instead?

Actually, with Windows Forms, you always want to use the
Invoke/BeginInvoke to make sure the code runs on the UI thread.

In fact, that is an easire solution to Dino's problem. Simply had a
reference to the ProgressBar in the FTP code and use BeginInvoke to fire
off any updates on the UI thread.
 
OK, I understand that. Only one more thing, how to make it reaise event
when it has downloaded 8 or so kb?

I have a sub DownloadFile that downloades file from FTP server, but don't
know how to check for the number of bytes downloaded and then reaise event
while it downloads the bytes.

If you're downloading the file, you must be in a loop somewhere pulling
the data over the port. In there, keep a counter going and after 8k
comes down, update the progressbar.

Also, from Robert Jacobson's reply, the easiest way to get the
ProgressBar update would be to:

1) Put the FTP code in a differen thread.
2) Make sure the FTP code has a reference to the progessbar
3) Use BeingInvoke on the progress bar to update it from the FTP thread.
 
Back
Top