Re: Threads & NSTextView
Re: Threads & NSTextView
- Subject: Re: Threads & NSTextView
- From: Laurent Michel <email@hidden>
- Date: Sun, 24 Jul 2005 07:56:59 -0400
On Jul 23, 2005, at 12:50 PM, Chris Hanson wrote:
On Jul 23, 2005, at 8:16 AM, Laurent Michel wrote:
Since I did not see NSTextView listed in the thread-safe cocoa
objects, I made sure to call
BOOL isLocked = [console lockFocusIfCanDraw];
...
if (isLocked) [console unlockFocus];
around the code that appends the text at the end of the
TextStorage object.
Appending text to an NSTextStorage is not a drawing operation.
How does one /properly/ locks an NSTextView to update its content
from a separate thread ? Should I lock the parent view ? How
should I lock ? which API ?
There is no way to properly lock it, because there's no way to
force Cocoa to use your lock when interacting with it.
This is true pretty much any time you're talking about using non-
thread-safe classes. If your code was the only thing interacting
with their instances, you might be able to lock around all uses.
However, since you're using a framework, your code isn't the only
code interacting with them, and you can't force code that isn't
yours to respect your locks.
You'll need to instead make sure that updating the text storage
happens on the main thread. This is just the kind of situation -
[NSObject performSelectorOnMainThread:withObject:waitUntilDone:] is
for.
-- Chris
Ok. performSelectorOnMainThread: did the trick. So, now, for
educational purpose, what is the intended use of this pair of methods
then ? (lockFocusIfCanDraw, and unlockFocus) ?
--
Laurent
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden