ios 線程

*******創建線程

    //線程
    //第一種
    /*
    //線程
    NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(sum) object:nil];
    //給線程起名字
    thread.name = @"thread";
    //啓動線程
    [thread start];
     
     //關閉
     [thread cancel];
     */
    //第二種
//    [NSThread detachNewThreadSelector:@selector(sum) toTarget:self withObject:nil];
    
    //第三種
//    [self performSelectorInBackground:@selector(sum) withObject:nil];
    
//    NSOperation的子類
    //第四種
    NSInvocationOperation *inOp = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(inVocation) object:nil];
//    [inOp start];
    
    //第五種
    NSBlockOperation *blOp = [NSBlockOperation blockOperationWithBlock:^{
        NSLog(@"我是block");
    }];
    

    //創建隊列
    NSOperationQueue *queue = [[NSOperationQueue alloc] init];
    //設置最大同時執行數量
    queue.maxConcurrentOperationCount = 2;
    //添加事件
    [queue addOperation:inOp];

    [queue addOperation:blOp];
    


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章