Re: Threads, safeness, and AutoreleasePools
Re: Threads, safeness, and AutoreleasePools
- Subject: Re: Threads, safeness, and AutoreleasePools
- From: Rainer Brockerhoff <email@hidden>
- Date: Wed, 15 Aug 2001 10:34:43 -0300
>
Date: Wed, 15 Aug 2001 09:03:42 +0200
>
From: Raphael Sebbe <email@hidden>
>
>
On Wednesday, August 15, 2001, at 04:59 AM, Todd Heberlein wrote:
>
>
> I have been experimenting with NSThreads, and I had a couple
>
> questions. At
>
> the bottom is a sample method I am testing. It is executed in a new
>
> thread
>
> with the detachNewThread:Selector:toTarget:withObject: method.
>
>
>
> First, does Apple discourage us from sending a message to an AppKit
>
> object
>
> from a separate thread? For example, in the code below I send the
>
> setIntvalue to an NSTextField object. Is this OK? Are there other
>
> steps I
>
> should do?
>
>
This is not OK. Only the main thread can access GUI objects.
>
>
You have a number of solutions to do that : DO (see NSConnection doc),
>
NSPort and NSPortMessage, AppleEvents, pipes...
Simply use:
[NSApplication detachDrawingThread:toTarget:withObject:]
instead of
[NSThread detachNewThread:Selector:toTarget:withObject:]
this will allow your detached thread to set GUI object's values.
--
Rainer Brockerhoff <email@hidden>
Belo Horizonte, Brazil
"In the affairs of others even fools are wise
In their own business even sages err."
http://www.brockerhoff.net/ (updated July 2000)