Re: NSPanel as Sheet and controlling the run loop
Re: NSPanel as Sheet and controlling the run loop
- Subject: Re: NSPanel as Sheet and controlling the run loop
- From: Steve Palmer <email@hidden>
- Date: Fri, 9 Apr 2004 17:45:39 -0700
Pardon me for jumping in, but I have a similar problem that I haven't
been able to solve. Basically I put up a sheet and kick off a thread.
When the thread is done, it uses performSelectorOnMainThread to call a
routine that I use to dismiss the sheet. The problem is that the sheet
doesn't get dismissed until I move the mouse even slightly. Here's the
(shortened) code:
{
[NSApp beginSheet:updateWindow modalForWindow:window modalDelegate:nil
didEndSelector:nil contextInfo:nil];
[progressBar startAnimation:self];
[NSApp runModalForWindow:updateWindow];
[progressBar stopAnimation:self];
[NSApp endSheet:updateWindow];
[updateWindow orderOut:self];
}
-(void)threadDone:(NSNotification *)aNotification
{
[NSApp stopModal];
}
I put a breakpoint on the [NSApp stopModal] in threadDone and confirmed
that it was called. I moved the breakpoint to [NSApp endSheet:...] and
I noticed that it wasn't hit until I forced an event such as moving the
mouse. So I'm curious about what I'm possibly missing here?
Thanks!
On Apr 8, 2004, at 6:22 AM, Louis C. Sacha wrote:
>
Hello...
>
>
Actually, I don't think NSNotifications provide the kind of thread
>
safety you imply. In fact, they are a bit dangerous in that regard,
>
since (as far as I know) the registered methods for observers are
>
actually run in the same thread that posts the notification.
>
>
You would probably need to use one of the performSelectorOnMainThread:
>
variants to force the notification to be posted on the main thread.
>
>
>
Louis
>
>
...
>
> If processing is going to take longer than this amount of time, then
>
> rather decouple the processing from the UI thread by spawning another
>
> thread that actually does the processing and reports back to the UI
>
> by sending notifications of progress via NSNotificationManager. The
>
> use of notifications nicely decouples the two threads. I personally
>
> do not like using NSNotifications, and use a model based on the
>
> Smalltalk dependency patterns, although this introduces some
>
> additional complexity in terms of making sure two threads do not
>
> attempt to access shared data at the same time, which is not a
>
> problem when using NSNotifications.
>
>
>
> Hope this comment is of value.
>
>
>
> Vincent
>
_______________________________________________
>
cocoa-dev mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.