Threaded Access to Display Elements

  • I'm struggling with some display problems in my multi-threaded application.

    I have a status bar and a progress bar in the bottom of my app's window.
    The status field (an NSTextField) is always there, updated as the user
    changes the active selection, or when a long operation is completed to
    report the status.  The progress bar is hidden, only present when they do
    some lengthy operation.

    The lengthy operations are done in a separate thread, of course.  This works
    fine, except with respect the to the updates to these two interface
    elements.  Updates to these fields is rather random.  It works perfectly
    sometimes, and is all messed up at others.  Of course, if I do the
    operations synchronously, all is well.

    For example, occasionally the status field is all overdrawn (e.g. the old
    text is still there, the new text scribbles all over it, making a mess).
    Not always, just some times.  The one that is driving me most nuts is the
    progress indicator.  It works, updates correctly, but I want it to hide when
    the operation is complete.  I "setHidden" and then do a "display" on the
    progress bar, in the worker thread when it is done.  Sometimes it works,
    other times it doesn't, the progress bar remains on the screen.

    Clearly I have conflicts with these controls because of the threaded nature.
    And so, my question is, what is the best way to handle this kind of
    interaction, to be sure the controls are properly updated from down in a
    worker thread?

    Thanks,
    Chris
  • On 23 Sep 07, at 13:56, Chris Williams wrote:
    > I'm struggling with some display problems in my multi-threaded
    > application.
    <...>
    > And so, my question is, what is the best way to handle this kind of
    > interaction, to be sure the controls are properly updated from down
    > in a
    > worker thread?

    performSelectorOnMainThread. Accept no substitutes.
  • Seems perfectly logical.  Thx.

    On 9/23/07 2:11 PM, "Andrew Farmer" <andfarm...> wrote:

    > On 23 Sep 07, at 13:56, Chris Williams wrote:
    >>> I'm struggling with some display problems in my multi-threaded
    >>> application.
    > <...>
    >>> And so, my question is, what is the best way to handle this kind of
    >>> interaction, to be sure the controls are properly updated from down
    >>> in a
    >>> worker thread?
    >
    > performSelectorOnMainThread. Accept no substitutes.
    >
previous month september 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Go to today