At 12:01 -0700 17/10/10, [email protected] wrote:
>From: eveningnick eveningnick <[email protected]>
>Date: Sun, 17 Oct 2010 20:25:02 +0300
>Message-ID: <[email protected]>
>
>So, i decided to do the following - i will execute the "long action"
>in a main thread, and create an "Esc-listening thread" that will
>install a system-wide keyboard EventTap (which watches ESC presses,
>and if it gets any, it rises the cancellation flag - this flag is
>periodically checked in the main thread's "long alhorithm").
>
>The thing i can't understand - is how to make that secondary thread to
>have a run loop, and how to make it not to finish as soon as i have
>created it - but to watch its own run loop for "event taps"'s events.
You create the secondary thread, install the event tap in it as usual - that
is, create a run loop source for the tap and add the source to the current run
loop returned by CFRunLoopGetCurrent() - and then, erhm, run the run loop in a
loop :-)
Something like (warning: typed in Eudora):
while (someCondition) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
SInt32 result =
CFRunLoopRunInMode(kCFRunLoopDefaultMode,0.5,YES);
[pool drain];
if (result==kCFRunLoopRunStopped)) {
return;
}
}
should work.
HTH,
--
Rainer Brockerhoff <[email protected]>
Belo Horizonte, Brazil
"In the affairs of others even fools are wise
In their own business even sages err."
Blog: http://brockerhoff.net/blog
_______________________________________________
Cocoa-dev mailing list ([email protected])
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]