问题描述
|
尝试看起来像这样的代码时,主要用于测试
NSInvocationOperation *operation = [NSInvocationOperation alloc];
operation = [operation initWithTarget:self
selector:@selector(dosignup:)
object:params];
while ( ![operation isFinished] ) [NSThread sleepForTimeInterval:0.1];
[operation release];
dosignup永远不会被调用。因此,我不得不假设在主线程处理完该选择器之前不会调用该选择器,而不是在诸如fork和/或.NET上的线程之类的队列插入时进行调用……总之要强制队列来处理该线程吗?
解决方法
您必须将操作添加到NSOperationQueue,或者必须手动启动它。
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(dosignup:) object:params];
[queue addOperation:operation];
[operation release];
[queue release];
要么
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(dosignup:) object:params];
[operation start];
但是我不知道您真正想做什么,因为您的代码现在几乎没有意义。
,您需要调用ѭ3才能执行。请注意,ѭ4是非并发的,因此它将同步执行并且不会产生线程。这意味着您当前的实现大致与此代码相同:
[self dosignup:params];