作者zonble (zonble)
看板MacDev
标题Re: [问题] 从 main thread perform 其他的 thread
时间Sat Oct 2 03:36:25 2010
※ 引述《sinread (电脑真耗钱)》之铭言:
: 小弟有一段code如下, 请各位先进给我一点意见:
: - (void)StreamStart
: {
: NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
: while(!exitNow)
: {
: [videoStream Connect];
: }
: [pool release];
: }
: 当UIPickerView被选取到某个row, 会变换 channel, 但是我目前这样的写法, 无法从
: main thread 去 perform streamThread,
: 请问我该怎麽做才可以让两个thread 沟通?
我们来读一下文件,performSelector:onThread:withObject:waitUntilDone:
的解释这麽说:
This method queues the message on the run loop of the target
thread using the default run loop modes
在你的 selector 里头,并没有开 runloop,所以程式不断在那段回圈
里头跑,外面的 message 想来也因此传不进去。
我试着了解你的程式的意图,大抵上就是在背景用回圈不断的用 connect
这个 method 来取得 video stream 的资料,而值此同时又想要可以改变
video stream 的 channel id。想想好像不一定要把改 channel 这件事情
丢到另外一个 thread 来做,大不了可以把现在的 Thread 取消掉,改了
channel id 之後再另外开一个 Thread,我也不清楚每次 connect 会多久,
如果每次 connect 的时间都很短的话,也可以把 channel id 写到别的地
方去,每次回圈里头的东西开始前,都先问问使用者要的 channel id 与
videoStream 物件里头的 channel id 是不是一样。
话说这是在写像 AverTV 那样的东西吗?(歪头)
--
zonble.net
cocoa.zonble.net
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 114.44.184.85