美文网首页
线程保活

线程保活

作者: 魏志军 | 来源:发表于2020-01-09 14:20 被阅读0次

    #import "ViewController.h"

    #import "WZJthread.h"

    @interface ViewController ()

    @property (nonatomic, strong) WZJthread *thread;

    @end

    @implementationViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

        // Do any additional setup after loading the view.

        self.thread = [[WZJthread alloc] initWithTarget:self selector:@selector(run) object:nil];

        [self.thread start];

    }

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent*)event{

        [self performSelector:@selector(text) onThread:self.thread withObject:nil waitUntilDone:NO];

    }

    //下面这个方法是在这个线程所做的事情

    - (void)text{

        NSLog(@"%s",__func__);

    }

    //下面这个方法只为了保住这个线程

    - (void)run{

        [[NSRunLoop currentRunLoop] addPort:[[NSPort alloc] init] forMode:NSDefaultRunLoopMode];

        [[NSRunLoop currentRunLoop] run];

    }

    @end

    相关文章

      网友评论

          本文标题:线程保活

          本文链接:https://www.haomeiwen.com/subject/czuyactx.html