转自 http://my.oschina.net/u/936286/blog/159245
01 | - ( BOOL )application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions |
03 | self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; |
06 | NSThread * thread = [[NSThread alloc] initWithTarget:self selector:@selector(run:) object:@ "universe" ]; |
12 | [NSThread detachNewThreadSelector:@selector(run:) toTarget:self withObject:@ "yuzhou" ]; |
16 | [self performSelectorInBackground:@selector(run:) withObject:@ "nsobject thread" ]; |
19 | NSOperationQueue *oprationQueue = [[NSOperationQueue alloc] init]; |
20 | [oprationQueue addOperationWithBlock:^{ |
22 | NSLog(@ "oprationQueue" ); |
24 | [oprationQueue release]; |
27 | NSOperationQueue *oprationQueue1 = [[NSOperationQueue alloc] init]; |
28 | oprationQueue1.maxConcurrentOperationCount = 1; |
31 | NSInvocationOperation *invation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(run:) object:@ "invation" ]; |
32 | [oprationQueue1 addOperation:invation]; |
36 | NSInvocationOperation *invation2 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(run2:) object:@ "invocation2" ]; |
37 | invation2.queuePriority = NSOperationQueuePriorityHigh; |
38 | [oprationQueue1 addOperation:invation2]; |
41 | [oprationQueue1 release]; |
44 | [self performSelectorOnMainThread:@selector(onMain) withObject:self waitUntilDone:YES]; |
48 | dispatch_queue_t queue = dispatch_queue_create( "name" , NULL); |
50 | dispatch_async(queue, ^{ |
55 | dispatch_sync(dispatch_get_main_queue(), ^{ |
56 | Boolean isMain = [NSThread isMainThread]; |
64 | self.window.backgroundColor = [UIColor whiteColor]; |
65 | [self.window makeKeyAndVisible]; |
71 | Boolean b = [NSThread isMainThread]; |
73 | NSLog(@ "onMain;;%d" ,b); |
78 | - ( void ) run:(NSString*)str |
80 | NSLog(@ "多线程运行:::%@" ,str); |
82 | - ( void ) run2:(NSString*)str |
84 | NSLog(@ "多线程运行:::%@" ,str); |