IOS在子线程中使用定时器,将定时器添加至RunLoop中
来源:互联网 发布:如何编写app软件 编辑:程序博客网 时间:2024/05/16 12:14
(BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];//用NSObject的方法创建一个多线程
[self performSelectorInBackground:@selector(multiThread) withObject:nil];self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}(void)multiThread
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
if (![NSThread isMainThread]) {// 第1种方式//此种方式创建的timer已经添加至runloop中
// [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(timerAction) userInfo:nil repeats:YES];
//保持线程为活动状态,才能保证定时器执行
// [[NSRunLoop currentRunLoop] run];//已经将nstimer添加到NSRunloop中了//第2种方式//此种方式创建的timer没有添加至runloop中
NSTimer *timer = [NSTimer timerWithTimeInterval:1.0f target:self selector:@selector(timerAction) userInfo:nil repeats:YES];
//将定时器添加到runloop中
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
[[NSRunLoop currentRunLoop] run];
NSLog(@”多线程结束”);
}
[pool release];
}(void)timerAction
{
//定时器也是在子线程中执行的
if (![NSThread isMainThread]) {
NSLog(@”定时器”);
}
}
- IOS在子线程中使用定时器,将定时器添加至RunLoop中(转)
- IOS在子线程中使用定时器,将定时器添加至RunLoop中
- IOS在子线程中使用定时器,将定时器添加至RunLoop中
- IOS在子线程中使用定时器,将定时器添加至RunLoop中
- IOS在子线程中使用定时器,将定时器添加至RunLoop中
- 在子线程中使用定时器,将定时器添加到RunLoop中
- ios之在子线程中使用定时器
- iOS中定时器和RunLoop的设定
- iOS使用定时器,并添加到子线程运行
- 子线程中执行定时器
- 在线程中使用定时器的例子!
- 在线程中启动定时器~
- 线程中使用多媒体定时器
- iOS中定时器NSTimer使用
- iOS中定时器的使用
- iOS中定时器NSTimer使用
- iOS中定时器NSTimer使用
- iOS中定时器NSTimer使用
- 彻底学会使用epoll(四)——ET的写操作实例分析
- hdu 5867
- 将动态库打包在Jar包并调用的方法
- SQL Server 存储过程嵌套处理 错误提示:INSERT EXEC 语句不能嵌套
- 分布式服务框架 Dubbo
- IOS在子线程中使用定时器,将定时器添加至RunLoop中
- c++ find 在容器中查找元素
- 彻底学会使用epoll(五)—— ET模式下的注意事项
- Notificationt通知栏使用详解
- Message Flood 【排序--二分查找】
- 数据结构——13 队列链表描述
- java web过滤器实际应用(解决中文乱码 html标签转义功能 敏感字符过滤功能)
- c/c++ 内存泄露分析工具
- android listview 实现时光轴效果