你如何更新从中创建图形用户界面,但不是在创建线程另一个阶级的胜利形式的控制(例如标签,进度条)? (例如,Program.cs中的事件处理程序)
how do you update a win forms control (ex. label, progress bar) from another class which created the GUI but not in the creating thread? (for example, an event handler of Program.cs)
我发现关于使用invoke()方法从另一个线程更新界面的几个职位,但我已经什么如果代码写在同一个班的形式迄今为止发现的唯一作品
I've found several posts regarding updating GUI from another thread using Invoke() method, but what i've found so far only works if the codes are written in the same class as the form
的 www.yoda.arachsys/csharp/threads/winforms.shtml
推荐答案您需要调用调用形式方法。例如:
You need to call the Invoke method on the form. For example:
private void someMethod() { myOtherForm.Invoke(new MethodInvoker(delegate() { // update things in myOtherForm here })); }如果您不需要返回回前完成更新方法,你应该使用的BeginInvoke 而不是调用。
If you don't need the updates to be finished before returning back to the method, you should use BeginInvoke instead of Invoke.
更多推荐
如何更新从另一个类Windows窗体GUI?
发布评论