Exit runloop and restart application

Discussion in 'Mac Programming' started by mehdies, Jun 29, 2013.

  1. mehdies macrumors member

    Jun 10, 2012
    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];
  2. gnasher729 macrumors P6


    Nov 25, 2005
    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?
  3. cqexbesd macrumors regular

    Jun 4, 2009
    If you really want to restart from scratch you could just re-exec yourself or maybe setjmp/longjmp?
  4. mehdies thread starter macrumors member

    Jun 10, 2012
    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.


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

Share This Page