GCD 高级用法(一) dispatch after
2015-03-27 13:05
771 查看
- (void)viewDidLoad {
[super viewDidLoad];
//————————————dispatch_after(一定时间后,将执行的操作加入到队列中)————————————
// <#dispatch_time_t when#> 指定时间
//1.第一种用法
/* NSEC_PER_SEC 秒
* NSEC_PER_MSEC 毫秒
* NSEC_PER_USEC 微秒
*/
dispatch_time_t time=dispatch_time(DISPATCH_TIME_NOW, 3ull *NSEC_PER_SEC);
dispatch_after(time, dispatch_get_main_queue(), ^{
//执行操作
NSLog(@"after 3s");
});
//2.第二种用法
//<#dispatch_function_t work#> --执行的c语言方法
dispatch_after_f(dispatch_time(DISPATCH_TIME_NOW, 3ull *NSEC_PER_SEC), dispatch_get_main_queue(), NULL, fun1);
//3.第三种用法
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5ull * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSLog(@"after 5s");
});
#warning mark -注意
//1.不是一定时间后执行相应的任务,而是一定时间后,将执行的操作加入到队列中(队列里面再分配执行的时间)
//2.主线程 RunLoop 1/60秒检测时间,追加的时间范围 3s~(3+1/60)s
}
void fun1()
{
NSLog(@"after 3s");
}
[super viewDidLoad];
//————————————dispatch_after(一定时间后,将执行的操作加入到队列中)————————————
// <#dispatch_time_t when#> 指定时间
//1.第一种用法
/* NSEC_PER_SEC 秒
* NSEC_PER_MSEC 毫秒
* NSEC_PER_USEC 微秒
*/
dispatch_time_t time=dispatch_time(DISPATCH_TIME_NOW, 3ull *NSEC_PER_SEC);
dispatch_after(time, dispatch_get_main_queue(), ^{
//执行操作
NSLog(@"after 3s");
});
//2.第二种用法
//<#dispatch_function_t work#> --执行的c语言方法
dispatch_after_f(dispatch_time(DISPATCH_TIME_NOW, 3ull *NSEC_PER_SEC), dispatch_get_main_queue(), NULL, fun1);
//3.第三种用法
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5ull * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSLog(@"after 5s");
});
#warning mark -注意
//1.不是一定时间后执行相应的任务,而是一定时间后,将执行的操作加入到队列中(队列里面再分配执行的时间)
//2.主线程 RunLoop 1/60秒检测时间,追加的时间范围 3s~(3+1/60)s
}
void fun1()
{
NSLog(@"after 3s");
}
相关文章推荐
- GCD高级用法(一):dispatch_after
- GCD高级用法-Dispatch I/O
- GCD高级用法(二) dispatch_group
- 完整具体解释GCD系列(二)dispatch_after;dispatch_apply;dispatch_once
- GCD之dispatch_after、dispatch_apply、dispatch_once等使用介绍
- iOS 多线程 GCD(滚床单) 的高级用法
- GCD高级用法-信号量
- iOS学习笔记74-完整详解GCD系列(二)dispatch_after;dispatch_apply;dispatch_once
- dispatch_after简单用法
- iOS GCD系列(一) dispatch_after;dispatch_apply;dispatch_once
- iOS开发之GCD(5)API dispatch_after
- swift详解之十七-----------GCD的一些高级用法
- Grand Central Dispatch (GCD) 用法详细介绍
- GCD 第二篇 dispatch_after;dispatch_apply;dispatch_once
- GCD(grand central dispatch)用法
- GCD中的dispatch_apply的用法及作用
- iOS 线程之GCD的高级用法
- GCD学习之dispatch_after
- GCD学习笔记(五):dispatch_after
- 完整详解swift GCD系列(二)dispatch_after;dispatch_apply;dispatch_once