469,572 Members | 1,222 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,572 developers. It's quick & easy.

Best Practice question

I am writing an application with a form that once started will run for
several minutes(an import). I would like the progress bar on the form to
update with the progress of the import. I would also like to be able to
minimize the form or move it around while the process is running.

I am guessing the best way to do this is with a seperate process that has an
event to fire off to the form when the progress bar update needs to happen?!

any suggestions would be great.

regards,
Jay
Nov 17 '05 #1
2 1263
Jay,
You could certainly achieve this using threads and that would probably make
most sense fromt he gui's perspective in making it as responsive as you can.
You could write your import routines in a seperate class that fires an event
when it finds something in the source file to import (like each line for
example). The main gui could hook the event and when it's fired update the
progress bar. You may want to pass inside your EventArgs parameter, the
total expected processing length and the current position so that your
progress bar has accurate info to update with (maybe the stream length and
position properties).
I think doing it this way though will slow your whole import process a bit.

Nev

"jayderk" <ja*****@hotmail.com> wrote in message
news:uZ**************@TK2MSFTNGP12.phx.gbl...
I am writing an application with a form that once started will run for
several minutes(an import). I would like the progress bar on the form to
update with the progress of the import. I would also like to be able to
minimize the form or move it around while the process is running.

I am guessing the best way to do this is with a seperate process that has an event to fire off to the form when the progress bar update needs to happen?!
any suggestions would be great.

regards,
Jay

Nov 17 '05 #2
"jayderk" <ja*****@hotmail.com> wrote in message
news:uZ**************@TK2MSFTNGP12.phx.gbl...
I am writing an application with a form that once started will run for
several minutes(an import). I would like the progress bar on the form to
update with the progress of the import. I would also like to be able to
minimize the form or move it around while the process is running.

I am guessing the best way to do this is with a seperate process that has
an
event to fire off to the form when the progress bar update needs to
happen?!


You should kick off a worker thread to do the work so that your GUI thread
stays responsive. In your design you will want to make sure that the worker
is stoppable if the user cancels or wants to close the window. The other
caveat is that your background thread cannot directly update controls on the
form; it must do so indirectly using Invoke.

About everything you would want to know to do this can be found in John
Skeet's excellent tutorial at
http://www.yoda.arachsys.com/csharp/threads/

-- Alan
Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by martin | last post: by
136 posts views Thread by Matt Kruse | last post: by
4 posts views Thread by Guy Noir | last post: by
3 posts views Thread by cbrown | last post: by
3 posts views Thread by Alan Isaac | last post: by
5 posts views Thread by Frank Millman | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.