我有一个应用程序,我正在运行一个单独的线程。在vb.net中运行线程
Dim thread As New System.Threading.Thread(AddressOf Main)
thread.Start()
但是,线程提到了一个文本框命名的输出,并生成在执行时出现此错误:
System.InvalidOperationException was unhandled
Message="Cross-thread operation not valid: Control 'Output' accessed from a thread other than the thread it was created on."
Source="System.Windows.Forms"
(消息缩短空间)
我怎样才能让运营在另一个线程上运行,但仍然使用Output对象?我无法调用子程序来为我做这件事,因为它会产生完全相同的错误。
顺便说一下,调用的方法是AppendText。
我可能在这里错过了一些重要的东西,所以感谢您的帮助!
里面分的样本? – Cyclone 2009-09-13 20:09:05
你能给一个代码示例吗? – Cyclone 2009-09-13 20:12:31
@Cyclone:看到这等岗位使用的InvokeRequired和调用的例子:http://stackoverflow.com/questions/571706/shortest-way-to-write-a-thread-safe-access-method-to-a- Windows的形式控制。 – 2009-09-13 20:20:42