Re: +[NSApp nextEventMatchingMask:...] from other thread
Re: +[NSApp nextEventMatchingMask:...] from other thread
- Subject: Re: +[NSApp nextEventMatchingMask:...] from other thread
- From: Ken Thomases <email@hidden>
- Date: Wed, 6 May 2009 12:36:52 -0500
On May 6, 2009, at 11:55 AM, Sidney San Martín wrote:
I recently found out that +[NSURLConnection
sendSynchronousRequest:...] leaks in Tiger, so I'm trying to write my
own implementation (these connections are already threaded and make
more sense to run synchronously). I use +[NSApp
nextEventMatchingMask:...] in the custom implementation to block until
the connection is finished, and it works great... in the main thread.
If I call my code from a different thread, nextEventMatchingMask:
returns nill instantly.
Run loops and event handling is a little bit above my current skill
level. How can I get the desired behavior here?
I think you're just looking for one of the -run... methods of NSRunLoop.
You don't actually need to process "events" in the sense of the term
as it appears in -nextEventMatchingMask:... (as opposed to the general
sense of the word "event" as "something happening"). That's referring
to a specific kind of event: GUI events received from the system or
NSEvents specifically posted to the event queue (-[NSApplication
postEvent:atStart:]).
For the purposes you describe, run loops and run loop sources should
be sufficient. I'm guessing that that's what you're already using,
even if you don't realize it, if you have a technique that's working
when you use -nextEventMatchingMask:... on the main thread.
Cheers,
Ken
_______________________________________________
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