我正在使用以下代码运行任务,
mTimerForImageUpload = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
if (mTimerForImageUpload) {
dispatch_source_set_timer(mTimerForImageUpload, dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC * uploadCheckInterval), NSEC_PER_SEC * uploadCheckInterval, leeway);
dispatch_source_set_event_handler(mTimerForImageUpload, ^{
[self uploadData];
});
dispatch_resume(mTimerForImageUpload);
}
基本上我希望同时只有一个运行该uploadData
方法的实例。即,如果任务仍在运行,我不想运行新线程,而是想等到它完成。
任何想法如何做到这一点?