Timer in the IOS-GCD

Source: Internet
Author: User

-(Ibaction) gcdresourcetestbtnpressed: (ID) sender

{

Initializes a GCD queue.

dispatch_queue_t timerqueue = dispatch_queue_create ("Timerqueue", 0);

Create a GCD timer.

_timersource = dispatch_source_create (dispatch_source_type_timer, 0, 0, timerqueue);

Double interval = 2 * NSEC_PER_SEC; Interval 2 seconds

Dispatch_source_set_timer (_timersource, Dispatch_time (dispatch_time_now, 0), interval, 0);

Timer block settings

Dispatch_source_set_event_handler (_timersource, ^{

NSLog (@ "%@", [Nsthread CurrentThread]);

Progresstotal + = 0.1;

Dispatch_async (Dispatch_get_main_queue (), ^{

[_progressview Setprogress:progresstotal];

});

});

Invoke the timer task.

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)}


Timer in the IOS-GCD

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.