基本概念
-(void)runTimerInThread
{//NSAutoreleasePool,没的用[NSTimer scheduledTimerWithTimeInterval:1.0target:self selector:@selector(doSth:) userInfo:self repeats:YES];//1.以上方法自动把NSTimer添加到RunLoop里面NSTimer* timer=[NSTimer timerWithTimeInterval:1.0target:self selector:@selector(doSth:) userInfo:self repeats:YES];//2.以上方法不会自动NSTimer添加到RunLoop里面[[NSRunLoop currentRunLoop]addTimer:timer forMode:NSDefaultRunLoopMode];//要手动加入runLoop,额额,类方法就写入了 addTimer:timer forMode:NSDefaultRunLoopMode;[[NSRunLoop currentRunLoop]run];//这很重要,把定时器的线程加入运行回环runloop才会使线程处于活跃状态}
定时器要加入runLoop才可以正常运行,但是要保证定时器的精确度,必须在不堵塞的多线程下进行
[self performSelectorInBackground:@selector(runTimerInThread) withObject:nil];
当然,你可以用CGD技术来处理多线程任务的