BackgroundWorkerProcess and GUI updates (progress windows)

M

Michael Jervis

Hi,

I'm writing a little application that scans a large number of media
files for processing.

The main application currently uses a backgroundworkerprocess to
perform the scan. Each media file has meta data extracted and is added
to one of a range of lists (pseudo-queues) for later processing. This
is all fine. But, I want to provide more feedback to the end user as to
progress as the process takes a considerable time.

To do so I have implemented a new modal dialog which outputs counts on
queues, and the current location in the filesystem that the scanning
has reached.

However, I have problems with this.

Firstly, I tried creating the new progress window in the main form
class, that then failed as when I tried to update the labels and
controls on the progress window I could not as the window was created
in another thread.

Then, I tried to create the progress window within the method that the
backgroundworkerprocess thread runs. This did not allow me to create a
modal dialog as I could not pass "this" into the constructor, because
the variable was not created in the same process.

I don't really want to move the logic into the progress window, because
I need to deal with the queues when populated.

This is just all seeming to be too much of a mess. Updating a progress
window is such a COMMON thing that applications do all the time. There
/must/ be a tried and tested pattern for doing so, I can't beleive that
..NET doesn't have a nice simple way to do this.

However, I've failed to find it so far. I'm new to .NET and winforms.
I've done some limited GUI programming in Delphi and a tiny bit in VB6,
I'm primarily an enterprise web application developer. i.e. I can code
well in the web paradigm, but my thick client gui stuff is almost
completely non-extant.

Any pointers to RTFM greatly accepted.

(Oh, .NET 2.0 in C# Express 2005)

Cheers,

Mike
 
A

Andy

RTFM.. ;-)

In your DoWork event handler, you'll have to use the
BackgroundWorker.ReportProgress method. DoWork should be adding to
the queues, and you UI should be handling the ProgressChanged event to
update the labels / progress bar.

HTH
 
M

Michael Jervis

Andy said:
RTFM.. ;-)

In your DoWork event handler, you'll have to use the
BackgroundWorker.ReportProgress method. DoWork should be adding to
the queues, and you UI should be handling the ProgressChanged event to
update the labels / progress bar.

I can't beleive I missed that...

Thanks a lot.
 

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