Best Practice question

J

jayderk

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
 
N

nevin

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
 
A

Alan Pretre

jayderk said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top