作者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
1F:→ 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)
2F:→ iterator:你的comet_hook, 等於是 while 里面不断create新thread 05/31 16:29
3F:→ iterator:你要写的东西应该不会是长这个样子的 05/31 16:32
那先不谈 我要写的程式好了 为何这个程式结果一直跑不出来呢?
※ 编辑: erspicu 来自: 111.254.13.14 (05/31 16:33)