无论如何,这听起来可能是一个新手问题,我对 GCD 很陌生
我有以下代码:
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);
}
someMethod 在哪里:
- (void)someMethod
{
NSLog(@"Thread 1");
}
如何在 someMethod 中更改 timer
的触发间隔属性?
最佳答案
我自己得到了答案,用新的间隔值调用 dispatch_source_set_timer
就足够了
关于iphone - GCD : How to change timer fire interval,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11070026/