作者erspicu (.)
看板C_Sharp
標題[問題] thread再問
時間Tue May 31 15:43:41 2011
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
→ james732:你的程式真的有必要寫個 while 迴圈一直跑嗎? 05/31 15:51
這只是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)
→ iterator:你的comet_hook, 等於是 while 裡面不斷create新thread 05/31 16:29
→ iterator:你要寫的東西應該不會是長這個樣子的 05/31 16:32
那先不談 我要寫的程式好了 為何這個程式結果一直跑不出來呢?
※ 編輯: erspicu 來自: 111.254.13.14 (05/31 16:33)