Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mehdies

macrumors member
Original poster
Jun 10, 2012
41
0
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 :

Code:
 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

Suspended
Nov 25, 2005
17,980
5,565
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 :

Code:
 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?
 

mehdies

macrumors member
Original poster
Jun 10, 2012
41
0
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 :


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 :


Code:
launchctl unload /Library/LaunchDaemons/daemon.plist


Code:
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 :


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


Code:
  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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.