On the 17th day of the 43rd month, the iOS child thread turns on and off the 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 is closed and will not be executed. 
}

 

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

 

Extra: When the main thread is processing some sliding operations, it will suspend the action in the timer. By modifying the mode, the event of the main thread sliding is prevented from blocking the events in the timer;

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


Guess you like

Origin www.cnblogs.com/javastart/p/12721433.html