如何在不导致(GUI)冻结的情况下处理长流程? [英] How can I process the long processes without causing the (GUI) to freeze ?

查看:87
本文介绍了如何在不导致(GUI)冻结的情况下处理长流程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!



我设计了一个具有很多功能的下载程序。但是这个程序的唯一问题是,当程序试图从互联网上创建下载链接时,(GUI)被冻结。



我有什么尝试过:



我尝试过BackgroundWorker课程。但它不适合我...因为在我的程序中,我必须在长处理操作期间更改某些控件属性的某些逻辑值,例如属性([Enabled]和[Visible])。并将项目添加到ComboBox中,这在BackgroundWorker类中是不允许的。





有没有人有另一种方法来执行能够在加工过程中更改控件属性的操作吗?



请给我帮助。



提前感谢我的兄弟。

Hello All !

I have designed a download program with a lots of features . But the only problem with this program is that the (GUI) is frozen when the program tries to create a download link from the Internet .

What I have tried:

I tried the BackgroundWorker class . But it is not suitable for me .. because in my program I have to change some of the logical values of the properties of some controls during the long processing operation , such as the properties ( [Enabled] and [Visible] ) . And adding the items to a ComboBox , which is not allowed in the BackgroundWorker class .


Does anyone have another way to perform the long operations with the ability to change the properties of controls during the processing operation ??

Please give me the help .

Thank you in advance my brothers .

推荐答案

使用后台工作程序的进度报告部分,并更新事件处理程序中的控件 - 即返回在UI线程上,所以它可以毫无问题地访问控件。这正是它的用途!



如果你想用一个实际的进度值加倍进度并执行这些控制命令,请通过命令为负百分比,进度值为正值。一个快速的枚举和一个切换来解密什么控件来更新你已经完成了。



可以通过调用它们来直接从BackgroundWorker中访问控件(这些是移动的你暂时回到UI线程)但是从OOPs POV做起来很麻烦 - 后台任务不应该知道前景控件。
Use the Progress reporting part of a Background worker, and update your controls in the event handler - that is back on the UI thread, so it can access controls without any problems. That is exactly what it is there for!

If you want to "double up" the progress with an actual progress value and "do these controls" commands, pass the commands as negative percentages, and the progress values as positive ones. A quick enum and a switch to decipher what controls to update and you are done.

It is possible to access controls directly from within the BackgroundWorker by Invoking them (which moves you temporarily back to the UI thread) but that's messy both to do and from a OOPs POV - background tasks shouldn't know about foreground controls.


这篇关于如何在不导致(GUI)冻结的情况下处理长流程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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