我的主窗体Form1
运行了我的程序的主体。C#获取原始线程来设置文本框的值
我有一个单独的线程开始执行算法。
当我从运行新线程的方法,方法MyAlgorithm()
我得到的错误
InvalidOperationException异常与消息,“控制控制的名字从比它创建的线程以外的线程访问。”
如何返回到原始线程以便我可以运行该方法以使用最新值更新我的文本框?
这是我想要运行的方法,包含在我的应用程序中的主要类Form1中。我已经看过Invoke()方法,但我不知道如何从线程方法获取我的Form1的原始实例。
我调用我的线程是这样的...
// Set the algorithm method up in it's own thread
Thread thread = new Thread(new ThreadStart(MyAlgorithm));
// Run the algorithm
thread.Start();
[跨线程操作无效:从其创建的线程以外的线程访问控件]的可能重复(http://stackoverflow.com/questions/142003/cross-thread-operation-not-valid -control-accessible-from-a-thread-other-the) – 2012-03-22 17:47:01