的确,在跨线程操作控件时需要对控件及其属性和方法的线程安全性(Thread Safety)加以留意,WinForm中的GUI控件并不是“线程安全”的。以下是MSDN中的一段叙述:******************************************************
Controls in Windows Forms are bound to a specific thread and are not thread safe. Therefore, if you are calling a control's method from a different thread, you must use one of the control's invoke methods to marshal the call to the proper thread. This property can be used to determine if you must call an invoke method, which can be useful if you do not know what thread owns a control. There are four methods on a control that are safe to call from any thread: Invoke, BeginInvoke, EndInvoke and CreateGraphics. For all other method calls, you should use one of these invoke methods when calling from a different thread.
******************************************************因此,当跨线程时,需要随时留意控件的线程安全问题。程序的很多看似匪夷所思的行为往往皆由跨线程导致。一些“重量级”控件尤其如此,如DataGrid等。这里有一片帖子就遇到了一个由于控件的线程安全性引起的问题,在后面给出了解决的方法以及例子代码,您不妨作为参考:http://www.csdn.net/expert/topic/871/871631.xml至于技巧,简单的说,在可能出现问题的时候,跨线程的控件方法调用最好不要直接调用方法本身,而是调用Control.BeginInvoke()、EndInvoke()以及Invoke()函数。除此之外,您还可以留意一下Control.InvokeRequired()方法。Hogwarts - S(u)ddenly dis@ppeared...

本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。  
为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。