4

I'm scheduling events on the main run loop using the following code:

[stream setDelegate:self];
[stream scheduleInRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
[stream open];

I assume that this means that NSStreamDelegate events are being scheduled on the main run loop and therefore can potentially impact UI responsiveness if frequent enough. This certainly seems to be the case in my program - even if the event handlers detach into a background thread without doing much work themselves.

How would I go about scheduling on a run loop other than mainRunLoop? Do I need to create a thread? Can I just create an NSRunLoop directly? What setup needs to be performed?

4

1 回答 1

0

我的建议是使用并发 nsoperstion。我在 github 上有一个演示应用程序,它显示了如何向这样的对象发送消息。你也会发现很多这样的项目。然后,您可以使用带有线程说明符的 performSelector 变体(此类操作的线程是持久的)。

该操作有一个运行循环,因此可以发送消息,一个线程,可以轻松取消,您可以创建多个。

于 2012-09-16T12:36:11.520 回答