Iphone操作队列线程什么时候真正启动?
当尝试看起来像这样的代码时,主要是为了测试
NSInvocationOperation *operation = [NSInvocationOperation alloc];
operation = [operation initWithTarget:self
selector:@selector(dosignup:)
object:params];
while ( ![operation isFinished] ) [NSThread sleepForTimeInterval:0.1];
[operation release];
dosignup 永远不会被调用。因此,我必须假设选择器不会被调用,直到主线程处理它,而不是在队列插入时(例如 .NET 上的 fork 和/或线程)...无论如何强制队列处理线程?
When trying code that looks like this, mainly for testing
NSInvocationOperation *operation = [NSInvocationOperation alloc];
operation = [operation initWithTarget:self
selector:@selector(dosignup:)
object:params];
while ( ![operation isFinished] ) [NSThread sleepForTimeInterval:0.1];
[operation release];
The dosignup never gets called. So then I have to assume that the selector does not get called until the main thread processes this, not at time of queue insert like a fork and / or a thread on .NET... Anyway to force the queue to processes the thread?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须将操作添加到 NSOperationQueue 中,或者必须手动启动它。
或者
但我不知道你真正想做什么,因为你的代码现在没有什么意义。
you have to add your operation to a NSOperationQueue or you have to start it manually.
or
But I don't know what you really want to do, because your code makes only little sense right now.
您需要调用
[操作开始]
才能执行。请注意,NSIncationOperation 是非并发的,因此它将同步执行并且不会生成线程。这意味着您当前的实现大致等于此代码:You will need to call
[operation start]
for it to execute. Be aware that theNSInvocationOperation
is non-concurrent so it will execute synchronously and not spawn a thread. This means that your current implementation is roughly equal to this code: