Objective-c中线程NSThread的使用
来源:互联网 发布:人工智能会议 2017 编辑:程序博客网 时间:2024/06/06 07:23
NSThread使用
1.创建并启动线程
thread = [[NSThread alloc]initWithTarget:self selector:@selector(startMonitor) object:nil];[thread start];
2.停止线程
先向线程发送cancel消息,将线程标记为停止,然后在合适的地方判断线程是否标记为退出,如果是,则发送exit消息,真正退出线程
- (void)getInfo:(id)sender{ if (!running) { NSLog(@"start monitor"); thread = [[NSThread alloc]initWithTarget:self selector:@selector(startMonitor) object:nil]; [thread start]; running = true; } else{ NSLog(@"stop monitor"); [thread cancel]; running = false; }}- (void) startMonitor{ while (true) { if ([[NSThread currentThread] isCancelled]) { [NSThread exit]; } //do your things here sleep(1); };}
- Objective-c中线程NSThread的使用
- objective-C多线程NSThread
- objective-C多线程NSThread
- objective-c - 基础篇 - 数据库网络 -- 进程和线程--NSThread
- iOS中NSThread线程
- 使用NSThread起线程
- NSthread线程使用
- 使用NSThread创建线程
- objective-c 中对于类的使用
- Objective-C中NSValue的使用
- Objective-C中NSValue的使用
- objective-c 中NSDictionary的使用
- Objective-C中字符串的使用
- Objective-C中数组的使用
- Objective-C中字典的使用
- Objective-C中NSValue的使用
- objective-c中self的使用
- Objective-C中NSValue的使用
- Android调用天气预报的WebService简单例子
- Android多线程断点下载jar包使用
- linux小记10 创建本地yum源
- 毫秒必争,前端网页性能最佳实践
- libdvbpsi库的使用
- Objective-c中线程NSThread的使用
- uva 10651- Pebble Solitaire(状态压缩DP)待看。。。
- 逆向并查集(ZOJ 3261)
- Oracle分区表,哈希分区的新建与增加
- Android开发之WebService介绍
- windows server 2012 AD 活动目录部署系列(十)操作主机角色转移
- 一些常用接口
- Android详细的对话框AlertDialog.Builder使用方法
- 第一个iOS程序–nib、xib与故事板的关系