Skip navigation.
 
mlCocoa binding and threads.
FROM : David Burnett
DATE : Mon Aug 14 19:18:00 2006

Hi,

I'm attempting to multi-thread my Cocoa application which is heavily
based on Cocoa Bindings using Core Data and I'm having GUI update issues.

At the moment it all works fine except that NSTableView that displays
the values from the Entities in the Managed Context does not update on
adding a new entity until either

I click on the window.
Move the mouse over a control that changes the cursor.
Change focus on/off the window.

They worked fine before I started to run this code of a new thread.

I understand that Bindings do not play to well with threads as the GUI
changes occur in the same thread as the value changes, and Cocoa prefers
it GUI changes in the main thread. To this end my thread runs like this

AddRandomGenomeToFlamesUsingContext
    createRandomGenomeInContext
        RenderThumbnail
        createGenomeEntity  (on main thread)
addNewFlame (on main thread)

The new Entity is created in createGenomeEntity and one of its values is
changed in AddNewFlame. Both are called using
performSelectorOnMainThread: withObject: waitUntilDone:YES so all of
the changes in the bound values should be performed on the main thread.

AddRandomGenomeToFlamesUsingContext is detached from an Action
responding to a button press.

I've tried calling

[flameTable performSelectorOnMainThread:@selector(setNeedsDisplay)
    withObject:nil waitUntilDone:YES];
   
[flameTable performSelectorOnMainThread:@selector(reloadData)
withObject:nil waitUntilDone:YES];

[oxidizerWindow
performSelectorOnMainThread:@selector(makeKeyAndOrderFront:)
withObject:self waitUntilDone:YES];

at the end of AddRandomGenomeToFlamesUsingContext, all to
no effect, so now I'm totally stumped.     

Any ideas ?

Dave

Related mailsAuthorDate
mlCocoa binding and threads. David Burnett Aug 14, 19:18
mlRe: Cocoa binding and threads. Bill Coleman Aug 16, 04:14
mlRe: Cocoa binding and threads. Chris Hanson Aug 16, 04:55
mlRe: Cocoa binding and threads. David Burnett Aug 16, 14:44
mlRe: Cocoa binding and threads. David Burnett Aug 16, 15:00
mlRe: Cocoa binding and threads. David Burnett Aug 16, 15:48
mlRe: Cocoa binding and threads. mmalc crawford Aug 16, 18:42
mlRe: Cocoa binding and threads. Chris Hanson Aug 16, 22:06