skpsmtpmessage在不同的线程 [英] skpsmtpmessage in different thread
问题描述
[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屋!