Re: Runloop not being stopped by CFRunLoopStop?
Re: Runloop not being stopped by CFRunLoopStop?
- Subject: Re: Runloop not being stopped by CFRunLoopStop?
- From: "email@hidden" <email@hidden>
- Date: Mon, 04 Jul 2011 17:59:28 +0100
On 4 Jul 2011, at 17:36, Matt Gough wrote:
> I have a runloop running in an NSThread. In this thread is a timer which fires every 2 seconds. In the timer, I check [NSThread isCancelled] and if so, stop the runloop via CFRunLoopStop.
>
> The runloop is run via runUntilDate:distantFuture.
>
> Shouldn't runUntilDate terminate once CFRunLoopStop has been called on it?
>
>
> I have verified that CFRunLoopStop is being called, but doGathering never finishes
>
> Any ideas?
>
1 idea.
In my case I call NSApp stop rather than accessing the runloop directly.
I find that the run loop will exit after the next event is dispatched.
If there is no next event then I don't see my runloop exit.
Therefore I generate a trigger event. Having a timer active isn't sufficient.
- (void)stopApp:(id)sender
{
#pragma unused(sender)
// will stop run loop after next actual event object dispatched.
// a timer doesn't count here
[NSApp stop:self];
// send a dummy event to trigger stopping
NSEvent *event = [NSEvent otherEventWithType:NSApplicationDefined
location:NSMakePoint(0,0)
modifierFlags:0
timestamp:0
windowNumber:0
context:nil
subtype:1
data1:1
data2:1];
[NSApp postEvent:event atStart:YES];
}
Regards
Jonathan Mitchell
Developer
Mugginsoft LLP
http://www.mugginsoft.com
_______________________________________________
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