Re: NSTimer Problem
Re: NSTimer Problem
- Subject: Re: NSTimer Problem
- From: Doug Brown <email@hidden>
- Date: Mon, 13 May 2002 15:23:32 -0700
Thanks for the note. I discovered that the hard way when I was making a
cocoa wrapper for BSD sockets :-)
For anyone who's interested, you can work around this by sending
messages back to the main UI thread from the second thread. Apple has a
good example that uses NSConnection on their web site. Basically, you
create two NSPorts with [NSPort port], create a connection with them,
and set the root object of the connection to the object you want to be
able to send messages to from the second thread. Next, put the ports in
an array and send the array as the object for
detachNewThreadSelector:toTarget:withObject: and make another
NSConnection with the ports reversed inside the thread. After doing
that, you can send messages to the proxy object (which you can get with
NSConnection's -rootProxy method) and those messages will be sent to the
object, but in the main/UI thread, not the second thread you just
detached. That is how I did it - I'm not sure if there are any better
ways to do it, but I'd be interested in hearing them if there are any.
Doug
On Monday, May 13, 2002, at 11:24 AM, email@hidden wrote:
Doug Brown wrote:
|I'm having what seems to be a very simple problem with NSTimers. I have
|a timer set up to repeatedly fire ... Is there a way to get it to keep
|firing even when the user is holding down the mouse on one of these
|buttons?
Brendan Younger wrote:
|Try placing your timer and your update code in a different thread.
This will work only if your timer routine doesn't do anything with the
UI. The AppKit methods are *not* thread-safe; fiddling with the UI from
a non-UI thread is a sure way to crash your program.
Glen Fisher
_______________________________________________
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.