Iphone操作队列线程什么时候真正启动?

发布于 2024-11-09 19:16:50 字数 486 浏览 1 评论 0原文

当尝试看起来像这样的代码时,主要是为了测试


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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

饮湿 2024-11-16 19:16:50

您必须将操作添加到 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];

但我不知道你真正想做什么,因为你的代码现在没有什么意义。

you have to add your operation to a NSOperationQueue or you have to start it manually.

NSOperationQueue *queue = [[NSOperationQueue alloc] init];

NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(dosignup:) object:params];
[queue addOperation:operation];
[operation release];

[queue release];

or

NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(dosignup:) object:params];
[operation start];

But I don't know what you really want to do, because your code makes only little sense right now.

_畞蕅 2024-11-16 19:16:50

您需要调用[操作开始]才能执行。请注意,NSIncationOperation 是非并发的,因此它将同步执行并且不会生成线程。这意味着您当前的实现大致等于此代码:

[self dosignup:params];

You will need to call [operation start] for it to execute. Be aware that the NSInvocationOperation 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:

[self dosignup:params];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文