zoukankan      html  css  js  c++  java
  • 延迟执行的几种方法

    第一种:

      [self performSelector:@selector(run) withObject:nil afterDelay:2.0];

     

    第二种:

      [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(run) userInfo:nil repeats:NO];

    第三种:最好

      dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

     

            NSLog(@"--------delay-------");

        });

     

    GCD中的时间单位是纳秒。

    延迟执行的原理是:先等2秒,再把任务提交到队列中执行。

  • 相关阅读:
    maskrcnn_benchmark代码分析(2)
    NoSQL现状
    CAP理论
    svn revert
    在SpringMVC中使用Jackson并格式化时间
    找了一个api管理工具
    SpringBoot读取application.properties文件
    MySQL性能优化的21个最佳实践 和 mysql使用索引
    Cannot subclass final class class com.sun.proxy.$Proxy
    AOP拦截器 表达式写法
  • 原文地址:https://www.cnblogs.com/dashengios/p/10409862.html
Copyright © 2011-2022 走看看