NSDrawerOpeningState woes

  • Hello,

    This one is only a minor annoyance but it looks like a tough nut to crack:
    I have an application whose main window has a drawer for logging. The
    application spawns a thread that does some scientific computations, logs
    the results and exits.

    It all works well except that there is no way I can have the drawer to
    open from within the secondary thread. The text view in the drawer does
    get updated but I won't see it if the drawer is not already opened.

    Now this thread does number crunching and does not have an event loop,
    which might well be the problem. The drawer will remain stuck in the
    NSDrawerOpeningState until after the termination of the secondary thread
    and will not even react to subsequent open messages from within the main
    thread (which of course has an event handler).

    Any suggestion?

    Jurgen
  • On Feb 4, 2008, at 12:31 PM, Jurgen Vermeiren wrote:

    > It all works well except that there is no way I can have the drawer to
    > open from within the secondary thread. The text view in the drawer
    > does
    > get updated but I won't see it if the drawer is not already opened.
    >
    > Any suggestion?

    You are calling the [drawer open] on the main thread by something like:

    [drawer performSelectorOnMainThread: @selector(open) withObject: nil
    waitUntilDone: YES];

    correct?  Because doing any sort of UI from secondary threads is
    usually wrong*, and likely to not work (or worse)

    (*if you are careful, you can draw into a view from a secondary thread)

    Glenn Andreas                      <gandreas...>
      <http://www.gandreas.com/> wicked fun!
    quadrium | flame : flame fractals & strange attractors : build,
    mutate, evolve, animate
  • Well, I was doing a simple performSelector, meaning that the logging
    method indeed was executed inside the secondary thread. The method in
    question was synchronized, though, and writing to the drawer text view
    from the thread did not seem to pose any problem. I'm not sure this
    qualifies as careful (to quote you) but I'm now doing the whole thing with
    performSelectorOnMainThread, which is certainly much safer and most of all
    solves the drawer opening problem.

    Many thanks!

    > On Feb 4, 2008, at 12:31 PM, Jurgen Vermeiren wrote:
    >
    >> It all works well except that there is no way I can have the drawer to
    >> open from within the secondary thread. The text view in the drawer
    >> does
    >> get updated but I won't see it if the drawer is not already opened.
    >>
    >> Any suggestion?
    >
    >
    > You are calling the [drawer open] on the main thread by something like:
    >
    > [drawer performSelectorOnMainThread: @selector(open) withObject: nil
    > waitUntilDone: YES];
    >
    > correct?  Because doing any sort of UI from secondary threads is
    > usually wrong*, and likely to not work (or worse)
    >
    > (*if you are careful, you can draw into a view from a secondary thread)
    >
    >
    > Glenn Andreas                      <gandreas...>
    > <http://www.gandreas.com/> wicked fun!
    > quadrium | flame : flame fractals & strange attractors : build,
    > mutate, evolve, animate
previous month february 2008 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    
Go to today
MindNode
MindNode offered a free license !