使用GUI进行多线程 [英] Mutlithreading with GUI

查看:83
本文介绍了使用GUI进行多线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我对线程不熟悉.
我曾尝试使用Google谷歌搜索,但发现的建议均无法正常工作. 我有一个应用程序,可以计算表格上给定点的最短路线.
在每次迭代后,通过从起点到终点连接点来绘制最短路径.

Hi,

I am not familiar with threading.
I have tried googling but none of the suggestions I found work correctly.
I have an application that calculates the the shortest routes given points on the form.
The shortest route is draw after each iteration by connecting the points from start to finish.

this.workerThread = new Thread(new ThreadStart(this.DrawRoute));<br />
              this.workerThread.Start();<br />
              while (workerThread.IsAlive)<br />
              {<br />
<br />
                  Application.DoEvents();<br />
<br />
              }



这是我可以使用的代码,但是通过调用Application.DoEvents(),我无法在窗体运行时更新窗体. IE.使用新的最短路径更新标签.
还有另一种方法吗?我曾尝试使用委托,但似乎没有用,如果我只是使用workerThread.Start();它也不起作用.

感谢您的帮助.

克里斯



This is the code I have which works, but by calling the Application.DoEvents(), I am unable to update the form while it is running. ie. update a label with the new shortest route.
Is there another way of doing it? I have tried using delegates but that did not seem to work, and if I just use workerThread.Start(); it does not work either.

Thanks for any help.

Chris

推荐答案

您需要使用
You need to use the Invoke method to marshal calls from your worker thread back to your form.


这篇关于使用GUI进行多线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆