G
Guest
Hi!
I'm having some trouble with BackgroundWorker objects and making some
"heavy" work that is *not* supposed to be in the progress bar dialog itself.
I basically want to do something like this:
ProgressForm form = new ProgressForm();
form.Show();
// ... Do heavy work here ...
form.UpdateProgress(label, progressValue);
// ... More heavy work ...
// Done!
form.Close();
And by doing this, have ProgressForm coded so it dosen't lock up the UI.
Would this be possible? My problem is that doing the work in the
ProgressForm's DoWork event handler used by the BackgroundWorker is not an
option because that would make ProgressForm work-specific, which I'd really
dislike to see. I want a reusable progress dialog, not make the dialog
specific depending on the heavy work I wish to do.
So far most examples I've seen on the web seem to be about work-specific
progress dialogs where the "heavy work" is in the DoWork function itself.
So I've played around with constructing the ProgressForm with an argument
being a delegate to the calling class' "heavy work" function, that will be
called back by the DoWork() handler. The "heavy work" function would have a
ProgressInfo object as return value, which would contain the progress value
and label to use after it returns from being called in DoWork().
That seemed like a bright idea until I saw that I then need the work in its
own function, which makes me need to supply it with its set of arguments
(like an array of objects to process), and the only option I can then see is
the make such arrays and everything related to the "heavy work" fields in the
calling class. :-/
Is there a "pretty" way out this by keeping things reasonably simple and not
hardwiring my heavy work loop into/inside the progress bar dialog class
itself?
I'm having some trouble with BackgroundWorker objects and making some
"heavy" work that is *not* supposed to be in the progress bar dialog itself.
I basically want to do something like this:
ProgressForm form = new ProgressForm();
form.Show();
// ... Do heavy work here ...
form.UpdateProgress(label, progressValue);
// ... More heavy work ...
// Done!
form.Close();
And by doing this, have ProgressForm coded so it dosen't lock up the UI.
Would this be possible? My problem is that doing the work in the
ProgressForm's DoWork event handler used by the BackgroundWorker is not an
option because that would make ProgressForm work-specific, which I'd really
dislike to see. I want a reusable progress dialog, not make the dialog
specific depending on the heavy work I wish to do.
So far most examples I've seen on the web seem to be about work-specific
progress dialogs where the "heavy work" is in the DoWork function itself.
So I've played around with constructing the ProgressForm with an argument
being a delegate to the calling class' "heavy work" function, that will be
called back by the DoWork() handler. The "heavy work" function would have a
ProgressInfo object as return value, which would contain the progress value
and label to use after it returns from being called in DoWork().
That seemed like a bright idea until I saw that I then need the work in its
own function, which makes me need to supply it with its set of arguments
(like an array of objects to process), and the only option I can then see is
the make such arrays and everything related to the "heavy work" fields in the
calling class. :-/
Is there a "pretty" way out this by keeping things reasonably simple and not
hardwiring my heavy work loop into/inside the progress bar dialog class
itself?