title: invalidate NSTimer inside dispatch_async
body: <p>I am creating a game, and inside the game I need to get a time counter.</p>
  
  <p>I works great but when I scroll the map it stops and then when I finish scrolling it start again. I fix this with dispatch_async. Here is the code</p>
  
  <pre><code>dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  
                  timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self  selector:@selector(timeNext) userInfo:nil repeats:NO];
  
                  [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
  
                  [[NSRunLoop currentRunLoop] run]; 
              });
  </code></pre>
  
  <p>Timer:</p>
  
  <pre><code>__block NSTimer *timer;
  </code></pre>
  
  <p>But if the app goes to the background I need to stop this times (and when it get active it starts again).</p>
  
  <p>With this way I can scroll the map and the timer works well I try:</p>
  
  <pre><code>- (void)timeNext {
      [timer invalidate];
      }
  </code></pre>
  
  <p>and didin't work. Anyone knows how to stop it? or any other idea to accomplish this task?</p>