PDA

View Full Version : Exit runloop and restart application




mehdies
Jun 29, 2013, 02:02 AM
I have a runloop that loop a method.I want to exit runloop and restart application in certain cases.how do that?

my runloop source :

NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.2 target:object selector:@selector(objectMethod) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
[[NSRunLoop currentRunLoop] run];



gnasher729
Jun 29, 2013, 12:14 PM
I have a runloop that loop a method.I want to exit runloop and restart application in certain cases.how do that?

my runloop source :

NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.2 target:object selector:@selector(objectMethod) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
[[NSRunLoop currentRunLoop] run];

Think about what scheduledTimerWithTimeInterval: does.

Apart from that, your request is really weird and it seems you are asking for help to shoot yourself in the foot. What do you actually try to achieve?

cqexbesd
Jun 29, 2013, 12:31 PM
I have a runloop that loop a method.I want to exit runloop and restart application in certain cases.how do that?

If you really want to restart from scratch you could just re-exec yourself or maybe setjmp/longjmp?

mehdies
Jun 29, 2013, 10:48 PM
Think about what scheduledTimerWithTimeInterval: does.

Apart from that, your request is really weird and it seems you are asking for help to shoot yourself in the foot. What do you actually try to achieve?

I use this code snippet in application source code :


NSDictionary *activeApp = [[NSWorkspace sharedWorkspace] activeApplication];
appName = (NSString*)[activeApp objectForKey:@"NSApplicationName"];
i use this code for getting active(focused application's) name.application works good but when i logout and login again appName variable got null value!

* this code snippet exist in the runlooped method.

I find out when restart the daemon,it's works well! first i unload the daemon and load again with blow commands :


launchctl unload /Library/LaunchDaemons/daemon.plist



launchctl load /Library/LaunchDaemons/daemon.plist


I have another daemon(second daemon) like mentioned daemon when first daemon got null second daemon restart first daemon.but not works!

i use mentioned commands in second daemon like below :


system("launchctl unload /Library/LaunchDaemons/daemon.plist");



system("/bin/launchctl load /Library/LaunchDaemons/daemon.plist");



but these commands can't restart daemon.when i remove load command unload command works.

----------

If you really want to restart from scratch you could just re-exec yourself or maybe setjmp/longjmp?

Yes,i want to relaunch application again and exit() first process of application.