6
này nghe có vẻ một câu hỏi newbie dù sao, tôi rất mới để GCDGCD: Làm thế nào để thay đổi khoảng thời gian hẹn giờ lửa
Tôi đã mã sau:
int interval = 2;
int leeway = 0;
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
if (timer) {
dispatch_source_set_timer(timer, dispatch_walltime(DISPATCH_TIME_NOW, NSEC_PER_SEC * interval), interval * NSEC_PER_SEC, leeway);
dispatch_source_set_event_handler(timer, ^{
[self someMethod];
});
dispatch_resume(timer);
}
đâu someMethod là:
- (void)someMethod
{
NSLog(@"Thread 1");
}
Làm cách nào để thay đổi thuộc tính khoảng thời gian lửa của timer
trong someMethod?
Một mất nhiều thời gian từ 0 nano giây cho một bộ đếm thời gian 2 giây là một chút không hề khoan nhượng :) – Taryn