BackgroundWorkerProcess and GUI updates (progress windows)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael  Jervis

    BackgroundWorkerProcess and GUI updates (progress windows)

    Hi,

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

    The main application currently uses a backgroundworke rprocess 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
    backgroundworke rprocess 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

  • Andy

    #2
    Re: BackgroundWorke rProcess and GUI updates (progress windows)

    RTFM.. ;-)

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

    HTH


    Michael Jervis wrote:
    Hi,
    >
    I'm writing a little application that scans a large number of media
    files for processing.
    >
    The main application currently uses a backgroundworke rprocess 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
    backgroundworke rprocess 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

    Comment

    • Michael  Jervis

      #3
      Re: BackgroundWorke rProcess and GUI updates (progress windows)


      Andy wrote:
      RTFM.. ;-)
      >
      In your DoWork event handler, you'll have to use the
      BackgroundWorke r.ReportProgres s 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.

      Comment

      Working...