Why is my CFRunLoopTimer not firing?

I have a CFRunLoopTimer created within a C++ class as shown below:

#import <CoreFoundation/CoreFoundation.h>

void cClass::StartTimer()
{      
  if(!mActiveSenseTimer)
  {
    CFTimeInterval TIMER_INTERVAL = 5;
    CFRunLoopTimerContext TimerContext = {0, this, NULL, NULL, NULL};
    CFAbsoluteTime FireTime = CFAbsoluteTimeGetCurrent() + TIMER_INTERVAL;
    mTimer = CFRunLoopTimerCreate(kCFAllocatorDefault,
                                  FireTime,
                                  0, 0, 0,
                                  ActiveSenseTimerCallback,
                                  &TimerContext);

    NSLog(@"RunLoop:0x%x, TimerIsValid:%d, TimeIsNow:%f, TimerWillFireAt:%f",
          CFRunLoopGetCurrent(),
          CFRunLoopTimerIsValid(mActiveSenseTimer),
          CFAbsoluteTimeGetCurrent(),
          FireTime);
  }
}

void ActiveSenseTimerCallback(CFRunLoopTimerRef timer, void *info)
{
  NSLog(@"Timeout");
  CFRunLoopTimerContext TimerContext;
  TimerContext.version = 0;

  CFRunLoopTimerGetContext(timer, &TimerContext);
  ((cClass *)TimerContext.info)->Timeout();
}

Calling cClass::StartTimer() results in the following log output:

RunLoop:0x7655d60, TimerIsValid:1, TimeIsNow:389196910.537962, TimerWillFireAt:389196915.537956

However, my timer never fires. Any ideas why?

Answers


Quote from the docs

A timer needs to be added to a run loop mode before it will fire. To add the timer to a run loop, use CFRunLoopAddTimer. A timer can be registered to only one run loop at a time, although it can be in multiple modes within that run loop.

Also make sure your run loop doesn't die before the timer fires.


Need Your Help

how do i get this.name thought JavaScript?

javascript html5

&lt;img id="image1" name="image_Group1" src="1-1.png" onclick="update(this.src,this.name);"&gt;

text is not showing on label on google map marker

javascript html5 google-maps google-maps-api-3

The problem is very simple , everything is working fine , the only problem is:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.