Multithreaded NSView:setNeedsDisplay:
Multithreaded NSView:setNeedsDisplay:
- Subject: Multithreaded NSView:setNeedsDisplay:
- From: Rony Kubat <email@hidden>
- Date: Tue, 4 Dec 2007 01:03:53 -0500
Hello,
I'm trying to find the "correct" way to request a view to repaint from
a thread other than the main one. I've seen this question asked
before, but I haven't seen an answer that is both (1) elegant, and (2)
works. I was hoping that someone could point me in the right direction.
Say I have this:
NSView* view;
and I want to call
[view setNeedsDisplay:YES];
from a thread other than main.
From what I've read elsewhere, I would love to do something like this:
[view performSelectorOnMainThread:@selector(setNeedsDisplay:)
withObject:YES waitUntilDone:NO];
Unfortunately, this doesn't work because YES is not an object. My
current solution is to create a proxy method:
- (void) redisplay
{
[self setNeedsDisplay:YES];
}
And call it like this:
[view performSelectorOnMainThread:@selector(redisplay) withObject:YES
waitUntilDone:NO];
But this is ugly. Is there a better way? Bummer that setNeedsDisplay:
is not threadsafe. Bummer that it requires an argument at all...
Cheers,
-Rony Kubat
_______________________________________________
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