[問題] thread再問

看板C_Sharp (C#)作者 (.)時間14年前 (2011/05/31 15:43), 編輯推噓0(003)
留言3則, 2人參與, 最新討論串1/2 (看更多)
google 參考 http://www.switchonthecode.com/tutorials/working-with-the-wpf-dispatcher 還是一樣卡死阿..... private void button1_Click(object sender, RoutedEventArgs e) { Thread t1 = new Thread(comet_hook); t1.Start(); } public void comet_hook() { while (true) { System.Threading.Thread thread = new System.Threading.Thread( new System.Threading.ThreadStart( delegate() { richTextBox1.Dispatcher.Invoke( System.Windows.Threading.DispatcherPriority.Normal, new Action( delegate() { richTextBox1.AppendText("aaa"); } ) ); } )); thread.Start(); } } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 111.254.13.14

05/31 15:51, , 1F
你的程式真的有必要寫個 while 迴圈一直跑嗎?
05/31 15:51, 1F
這只是SAMPLE 實際上richTextBox1.AppendText("aaa"); 的地方 會是一個無限次自動重複掛載的HTTP物件動作 無限次的repeat 想來想去似乎只有while(true){...}好處理 ※ 編輯: erspicu 來自: 111.254.13.14 (05/31 15:58) ※ 編輯: erspicu 來自: 111.254.13.14 (05/31 16:22)

05/31 16:29, , 2F
你的comet_hook, 等於是 while 裡面不斷create新thread
05/31 16:29, 2F

05/31 16:32, , 3F
你要寫的東西應該不會是長這個樣子的
05/31 16:32, 3F
那先不談 我要寫的程式好了 為何這個程式結果一直跑不出來呢? ※ 編輯: erspicu 來自: 111.254.13.14 (05/31 16:33)
文章代碼(AID): #1Dv9mmLE (C_Sharp)
討論串 (同標題文章)
以下文章回應了本文
完整討論串 (本文為第 1 之 2 篇):
0
3
文章代碼(AID): #1Dv9mmLE (C_Sharp)