首页 新闻 搜索 专区 学院

非界面线程操作控件的问题

0
悬赏园豆:10 [已解决问题] 解决于 2008-08-28 15:37
<P><IMG id=Codehighlighter1_22_126_Open_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_22_126_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_22_126_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_22_126_Closed_Text').style.display='inline';" alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_22_126_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_22_126_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_22_126_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_22_126_Open_Text').style.display='inline';" alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" align=top><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;DoWork()&nbsp;</SPAN><SPAN id=Codehighlighter1_22_126_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG alt="" src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_22_126_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread&nbsp;t&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Thread(</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;ThreadStart(</SPAN><SPAN style="COLOR: #0000ff">this</SPAN><SPAN style="COLOR: #000000">.DoSomething));<BR><IMG alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t.Start();<BR><IMG alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_162_218_Open_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_162_218_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_162_218_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_162_218_Closed_Text').style.display='inline';" alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_162_218_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_162_218_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_162_218_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_162_218_Open_Text').style.display='inline';" alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;DoSomething()&nbsp;</SPAN><SPAN id=Codehighlighter1_162_218_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG alt="" src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_162_218_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MessageBox.Show(</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">thread&nbsp;start</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN></P> <P><SPAN><SPAN style="COLOR: #000000">如上代码,有个疑问,不是说对界面控件的更新是要在主线程上操作的吗?那为什么在新开的线程上也能操作啊,不太明白其中的道理,高手请指点</SPAN></SPAN></P>
lexus的主页 lexus | 初学一级 | 园豆:0
提问于:2008-08-27 21:20
< >
分享
最佳答案
0
所有在主线程上创建的控件,必须在主线程上进行操作 就是说,不能从一个线程操作在别的线程上创建的控件 你的代码里,MessageBox是在DoSomeThing的线程上创建的,因此没问题吧……
Gray Zhang | 专家六级 |园豆:17610 | 2008-08-27 21:36
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册