ipad – 睡眠或暂停NSThread

ipad – 睡眠或暂停NSThread,第1张

概述我正在创建一个新的Thread,它会在每一段时间后运行我的一个方法. 现在我正在做的如下: NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(setUpTimerThread) object:nil]; [thread start]; 上面的方法调用我的setUpTimerThraed方法,这个 我正在创建一个新的Thread,它会在每一段时间后运行我的一个方法.

现在我正在做的如下:

NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(setUpTimerThread) object:nil]; [thread start];

上面的方法调用我的setUpTimerThraed方法,这个方法生成一个NSTimer并在每1分钟后调用一个特定的方法,即syncdata.现在我想要的是我的同步数据方法是将一些文件发送到FTP文件夹.什么时候它发送一个文件到FTP我想让我的“线程”睡一会儿.

我用过

[NSThread sleepForTimeInterval:3.0];

但是这段代码阻止了我的应用主线程.有什么方法我只能睡一段时间我的“线程”线程,以便它不会停止我的应用程序响应3秒,并没有睡觉我的主线程.
希望你得到我要问的人.请帮忙?

解决方法 sleepForTimeInterval:休眠调用它的线程.尝试在要睡眠的线程上调用睡眠而不是主线程.

用你的当前睡眠呼叫替换

[self performSelector:@selector(sleepThread) onThread:thread withObject:nil waitUntilDone:YES];

然后实现这个方法

-(voID)sleepThread {    [NSThread sleepForTimeInterval:3.0];}
总结

以上是内存溢出为你收集整理的ipad – 睡眠或暂停NSThread全部内容,希望文章能够帮你解决ipad – 睡眠或暂停NSThread所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1080301.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存