Exit runloop and restart application

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

  1. macrumors member

    Joined:
    Jun 10, 2012
    #1
    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];
     
  2. macrumors G5

    gnasher729

    Joined:
    Nov 25, 2005
    #2
    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. macrumors member

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

    Joined:
    Jun 10, 2012
    #4
    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.

    ----------

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

Share This Page