title: PerformSelector After delay doesn't run in background mode - iPhone
body: <p>I have a voip application which runs constantly on the background as well.
  While I'm in the background I'm calling from the main thread: (to establish network connection in case I diagnose a network lost).</p>
  
  <pre><code>[self performSelector :@selector(Reconnect:) withObject:nil afterDelay:60.0];
  </code></pre>
  
  <p>However, the selector is only performed when my app returns to foreground.
  Should I do anything in particular to make the selector getting executed while in the background ?</p>
  
  <p>Thanks</p>
  
  <p><strong>Edit:</strong></p>
  
  <pre><code>-(void) reconectInBackgroundAfterDelay:(NSTimeInterval) dealy
  {
      NSLog(@"reconectInBackgroundAfterDelay");
      UIApplication*   app = [UIApplication sharedApplication];
  
      bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
          [app endBackgroundTask:bgTask];
          bgTask = UIBackgroundTaskInvalid;
      }];
  
      // Start the long-running task and return immediately.
      dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  
          [self performSelector :@selector(Reconnect:) withObject:nil afterDelay:dealy];
  
          [app endBackgroundTask:bgTask];
          bgTask = UIBackgroundTaskInvalid;
      });
  }
  </code></pre>
  
  <p>I added this code instead, but still the "Reconnect" method is not getting called after the provided delay.
  I call the "reconectInBackgroundAfterDelay" method while I'm already in the background.</p>
  
  <p>Any other suggestions ?</p>
  
  <p><strong>Edit 2</strong>
  Found a solution. See below</p>