2012-06-17 43 views
6

這聽起來可能是一個新手的問​​題,無論如何,我很新的GCDGCD:如何更改計時器防火間距

我下面的代碼:

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

如何在某些方法中更改timer的火災區間屬性?

+0

0納秒爲2秒定時器A餘地是有點無情:) – Taryn

回答

9

得到的答案我自己的,主叫dispatch_source_set_timer新的區間值足夠