NSTimer NSThread
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(UpdateTimerFunc:) userInfo:nil repeats:YES]; -(void)UpdateTimerFunc:(NSTimer *)theTimer { [updateGpsTimer invalidate];//stop timer return; }
NSThread *InitThread = [[NSThread alloc]initWithTarget:self selector:@selector(InitThreadFunc:) object:self]; [InitThread start]; -(void)InitThreadFunc:(id)sender { ViewController *fSelf = (ViewController*)sender; [g_soapReadUserMsgFromSql]; [selfloadWeather]; }
[self performSelectorOnMainThread:@selector(DuquDBQiye:) withObject:nil waitUntilDone:NO];
GCD实现异步
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ // 耗时的操作 dispatch_async(dispatch_get_main_queue(), ^{ // 更新界面 }); });
一组任务
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_group_t group = dispatch_group_create(); dispatch_group_async(group, queue, ^{ [NSThread sleepForTimeInterval:1]; NSLog(@"group1"); }); dispatch_group_async(group, queue, ^{ [NSThread sleepForTimeInterval:2]; NSLog(@"group2"); }); dispatch_group_async(group, queue, ^{ [NSThread sleepForTimeInterval:3]; NSLog(@"group3"); }); dispatch_group_notify(group, dispatch_get_main_queue(), ^{ NSLog(@"updateUi"); }); dispatch_release(group);