zoukankan      html  css  js  c++  java
  • NSThread的使用

    -(void)creatThread1

    {

        NSThread *thread =  [[NSThread alloc]initWithTarget:self selector:@selector(run:) object:@"abc"];

        thread.name = @"mythread";

        [thread start];

    }

    -(void)creatThread2

    {

        //不要开启,无法设置线程名称

        [NSThread detachNewThreadSelector:@selector(run:) toTarget:self withObject:@"miss"];

    }

    -(void)creatThread3

    {

        //开启后台线程

        [self performSelectorInBackground:@selector(run:) withObject:@"background"];

    }

    -(void)run:(id)obj{

        NSLog(@"current = %@",[NSThread currentThread]);

        for (int i = 0; i < 100000; i ++) {

            NSLog(@"--%d--",i);

        }

    }

    线程休眠

    [NSThread sleepForTimeInterval:2];

    [NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:2]];

    线程退出

    [NSThread exit];

  • 相关阅读:
    Oracle-DQL 7- 集合操作
    Oracle-DQL 6- 子查询
    Oracle-DQL 5- 分组函数(多行函数)
    Oracle-DQL 4- 多表查询
    Oracle-DQL 3- 单行函数
    构建gulp项目
    重开Vue2.0
    ES6
    emmet简单记录
    webpack 3.X研究
  • 原文地址:https://www.cnblogs.com/PJXWang/p/5948550.html
Copyright © 2011-2022 走看看