skpsmtpmessage在不同的线程 [英] skpsmtpmessage in different thread

查看:157
本文介绍了skpsmtpmessage在不同的线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在我的iPhone应用程序中成功实现了skpsmtpmessage。这样做很好,但它运行在主线程上,导致UI锁定,直到操作完成。因此,我已经尝试移动到第二个线程:

  [NSThread detachNewThreadSelector:@selector(launchJobWithJob :) toTarget:self withObject:职位描述]; 

如果我这样做,这个类似乎被卡在连接上,只有NSLog输出是:

  C:尝试连接到服务器:mail.example.com:25 

如果我通过进行 [self launchJobWithJob:jobDescription]; / / code>,它工作正常,但正如我之前所说,滞后。



我如何让它在后台线程中工作?有人遇到这个吗?



编辑:我尝试了 NSOperationQueue ,同样的事情再次发生,只是日志输出,没有别的!

  NSOperationQueue * queue = [NSOperationQueue new]; 

NSInvocationOperation * operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(launchJobWithJob :) object:jobDescription];

[queue addOperation:operation];

[操作版]


解决方案

我确定它的网络连接在runloop上,所以让线程的runloop运行直到操作完成。

  [[NSRunLoop currentRunLoop] run]; 


I have just successfully implemented skpsmtpmessage into my iPhone app. This works fine, but it runs on the main thread, causing the UI to lock up until the operation is complete. Therefore I have tried moving it to a second thread:

[NSThread detachNewThreadSelector:@selector(launchJobWithJob:) toTarget:self withObject:jobDescription];

If I do this that way, the class seems to get stuck on the connecting right away, with the only NSLog output being:

C: Attempting to connect to server at: mail.example.com:25

If I launch the job just by going [self launchJobWithJob:jobDescription];, it works fine but as I said before, lags heavily.

How can I get this to work in a background thread? Has someone come across this?

Edit: I have tried NSOperationQueue as well - the same happens again, just the log output and nothing else!

NSOperationQueue*queue = [NSOperationQueue new];

NSInvocationOperation*operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(launchJobWithJob:) object:jobDescription];

[queue addOperation:operation];

[operation release];

解决方案

I'm sure that it does its network connection stuff on the runloop, so let the runloop of the thread run until the operation is finished.

[[NSRunLoop currentRunLoop] run];

这篇关于skpsmtpmessage在不同的线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆