Threads and widgets
Threads and widgets
- Subject: Threads and widgets
- From: "Mike R. Manzano" <email@hidden>
- Date: Sat, 5 Mar 2005 00:27:49 -0800
Okay, here's one I can't figure out. I have this code being called
from a thread other than the main thread:
NSLog( @"%@/Scheduling postCanonicalNameNotification" , [ NSThread
currentThread ] ) ;
[ self performSelectorOnMainThread:
@selector(postCanonicalNameNotification)
withObject:nil waitUntilDone:NO ] ;
Here is the selector being performed:
- (void) postCanonicalNameNotification
{
NSLog( @"%@/postCanonicalNameNotification", [ NSThread currentThread ]
) ;
[ [ NSNotificationCenter defaultCenter ]
postNotificationName:kCanonicalNamesModifiedNotification
object:self ] ;
} // postCanonicalNameNotification
As you can see, this posts a notification on the default center. Here
is the one and only observer:
- (void) handleCanonicalNamesModifiedNotification: (NSNotification*)
notification
{
NSLog( @"cMainWindowController is handling
kCanonicalNamesModifiedNotification" ) ;
// Update the participants list
cFSModel* fsm = [ cFSModel instance ] ;
NSArray* participants = [ fsm allParticipantsAsCanonicalNames ] ;
// Sort them
participants = [ participants
sortedArrayUsingSelector:@selector(compare:) ] ;
// Remove all participants
[ _participants removeAllItems ] ;
// Add them back in
[ _participants addItemWithTitle:@"Show Everyone" ] ;
[ _participants addItemsWithTitles:participants ] ;
[ _participants setEnabled:YES ] ;
NSLog( @"cMainWindowController done handling
kCanonicalNamesModifiedNotification" ) ;
} // handleCanonicalNamesModifiedNotification:
According to the logs, the (non-main) thread is scheduling
postCanonicalNameNotification to be executed on the main thread, and it
is indeed being executed on the main thread. From what I understand of
notifications, handleCanonicalNamesModifiedNotification: should
subsequently execute on the main thread, and indeed it does.
Now, this seems to work just fine, and it works flawlessly every time.
However, if I click on the _participants widget (an NSPopupButton), and
play with it while it is open, the program eventually crashes. I'm
thinking it loses its brain because I am changing its menu items while
I'm playing with the widget at the same time, but I'm not sure if
that's the problem. Since the menu item updates are occurring in the
main thread, there shouldn't really be any race conditions, right? Some
other possibly important info: postCanonicalNameNotification: is called
fairly often (at least once a second), and
handleCanonicalNamesModifiedNotification: executes even when the popup
button is showing its menu (it doesn't block execution of the main
thread).
Can anyone help my trace down this crash?
Thanks,
Mike
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden