• 多线程NSThread基本用法


     
     
    #import "ViewController.h"

    @interface ViewController ()

    @end

    @implementation ViewController

    - (void)viewDidLoad {
        [super viewDidLoad];
       
        //开启多线程方法一
    //    [self performSelectorInBackground:@selector(threadAction) withObject:nil];
       
        //开启多线程方法二
    //    NSThread *thread = [[NSThread alloc]initWithTarget:self selector:@selector(threadAction) object:nil];
        //thread.name = @"thread1";
    //    NSLog(@"MAIN中:%@",thread);

    //    [thread start];
       
        //开启多线程方法三
    //    [NSThread detachNewThreadSelector:@selector(threadAction) toTarget:self withObject:nil];
       


       

        for (int i = 0; i < 50; i ++) {
            NSLog(@"main: %d",i);
        }
    }

    - (void)threadAction{
       
        NSThread *thread = [NSThread currentThread];
            NSLog(@"thread中:%@",thread);
       
        for (int i = 0 ; i < 50; i ++) {
            NSLog(@"thread:  %d",i);
           
            if (i==10) {
                [NSThread exit];
            }
           
            if ([NSThread isMultiThreaded]) {
                NSLog(@"是多线程");
            }
        }
    }

    @end
  • 相关阅读:
    C语言经典例题
    准确判断网络连接方式和当前连接状态
    [WMI实例]在网络连接断开时通知用户
    SciTE设置
    WQL语言初步
    以管理员身份运行bat
    AHK Primary
    AHK Run as Administrator In AHK
    为.VBS和.JS文件添加右键以管理员运行菜单
    PowerShell 随笔
  • 原文地址:https://www.cnblogs.com/chillytao-suiyuan/p/4834124.html
Copyright © 2020-2023  润新知