Re: [NSApp stop:]
Re: [NSApp stop:]
- Subject: Re: [NSApp stop:]
- From: "Michael Ash" <email@hidden>
- Date: Thu, 9 Oct 2008 21:01:54 -0400
On Thu, Oct 9, 2008 at 9:15 AM, Michiel de Hoon <email@hidden> wrote:
> Hi everybody,
>
> According to the documentation, [NSApp stop:] will break the flow of control out of the [NSApp run] method. While this is true, [NSApp run] doesn't notice that [NSApp stop:] was called until some other event comes along. So I call [NSApp stop:], nothing happens, and when I then move the mouse over one of the application windows [NSApp run] exits. Currently my workaround is to post a do-nothing event to NSApp to wake up the runloop:
>
> [NSApp stop: nil];
> NSEvent* event = [NSEvent otherEventWithType: NSApplicationDefined
> location: NSMakePoint(0,0)
> modifierFlags: 0
> timestamp: 0.0
> windowNumber: 0
> context: nil
> subtype: 0
> data1: 0
> data2: 0];
> [NSApp postEvent: event atStart: true];
>
> Then [NSApp run] exits immediately.
> But there must be a better way to do this. Does anybody know what the right way is to do this?
This sort of thing is surprisingly common. For example, autorelease
pools don't get drained until an event happens:
http://www.mikeash.com/?page=pyblog/more-fun-with-autorelease.html
The workaround you came up with seems to be standard operating
procedure for this kind of thing. I certainly don't know of a better
way, and I wouldn't worry about doing what you're doing.
Mike
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
References: | |
| >[NSApp stop:] (From: Michiel de Hoon <email@hidden>) |