作者cplusplus (C++)
看板C_Sharp
标题Re: [问题] 怎麽在thread里产生新的form?
时间Sun Mar 5 14:38:39 2006
: 我是打算写一个C++ 视窗网路程式。
: 用另一个thread专门听别人送封包过来。
: 如果送过来了。
: 就产生一个form显示那个人传讯息的内容。
: 就像是msn之类的,别人丢讯息过来,就会跳出一个视窗。
: 所以我才来问怎样在thread中产生视窗。
不好意思 昨日不在 回覆有点慢...
C# 不会自动为每个 form 产生各自的 UI thread
必须明确使用方法来为每个form产生一个 UI thread
( UI thread 就是负责该视窗 message handling 的 thread )
所以如果你用某个 thread 产生一个 form 而没有另外指定要有其独立的 UI thread
就糟糕啦~ 没人要负责啦~
C#里面用 Application.Run() 来完成这件事
当你在某个thread里面写下这一行 你这个thread就必须作为这个form的UI thread了
一个 thread 只能当一个 form 的 UI thread...
所以你想要的功能就是产生一个 thread 然後在thread里写下 Application.Run(new
YourForm())
就好了 其他接收讯息还有UI的功能就写在 YourForm 里面
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.115.217.14
1F:推 miewQ:谢谢你^^ 03/06 01:48