Re: [問題] 從 main thread perform 其他的 thread
※ 引述《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
討論串 (同標題文章)
MacDev 近期熱門文章
PTT數位生活區 即時熱門文章