码迷,mamicode.com
首页 > 移动开发 > 详细

IOS-GCD中的Timer

时间:2014-11-22 10:37:18      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:style   io   os   sp   strong   on   div   2014   log   

- (IBAction)gcdResourceTestBtnPressed:(id)sender

{

    /// 初始化一个gcd队列.

    dispatch_queue_t timerQueue = dispatch_queue_create("timerQueue", 0);

    /// 创建 gcd timer.

    _timerSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, timerQueue);

    

    double interval = 2 * NSEC_PER_SEC; /// 间隔2秒

    dispatch_source_set_timer(_timerSource, dispatch_time(DISPATCH_TIME_NOW, 0), interval, 0);

    

    /// 定时器block设置

    dispatch_source_set_event_handler(_timerSource, ^{

        NSLog(@"%@",[NSThread currentThread]);

        progressTotal += 0.1;

        dispatch_async(dispatch_get_main_queue(), ^{

            [_progressView setProgress:progressTotal];

        });

    });

    /// 唤起定时器任务.

    dispatch_resume(_timerSource);

}


2014-11-22 10:21:50.964 MultitThreadManagement[856:410093] <NSThread: 0x7fd8d3511a50>{number = 2, name = (null)}

2014-11-22 10:21:52.969 MultitThreadManagement[856:410093] <NSThread: 0x7fd8d3511a50>{number = 2, name = (null)}

2014-11-22 10:21:54.969 MultitThreadManagement[856:410093] <NSThread: 0x7fd8d3511a50>{number = 2, name = (null)}


IOS-GCD中的Timer

标签:style   io   os   sp   strong   on   div   2014   log   

原文地址:http://blog.csdn.net/a330416020/article/details/41379303

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!