第43月第17天 iOS 子线程开启、关闭runloop performSelector

1.

dispatch_async(dispatch_get_global_queue(0, 0), ^{
        
        [self performSelector:@selector(asdf) withObject:nil afterDelay:1];
        
        [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
    });

-(void)asdf
{
    CFRunLoopStop([NSRunLoop currentRunLoop].getCFRunLoop);
    
    dispatch_sync(dispatch_get_global_queue(0, 0), ^{
        [self performSelector:@selector(asdasd) withObject:nil afterDelay:5];
    });
}

-(void)asdasd
{
    //runloop已关闭,不会执行。
}

https://www.jianshu.com/p/8e6d51f69ca3

额外:当主线程在处理一些滑动操作是,会暂停定时器中的动作,通过修改mode,防住 主线程滑动等事件阻碍了定时器中的事件;

timer = [NSTimer timerWithTimeInterval:5.0 target:self selector:@selector(SendHeartBeat) userInfo:nil repeats:YES];
 [[NSRunLoop mainRunLoop] addTimer:heartTimer forMode:NSRunLoopCommonModes];

https://www.cnblogs.com/lolDragon/articles/5893375.html


原文地址:https://www.cnblogs.com/javastart/p/12721433.html