VB6 应用程序停止响应 [英] VB6 Application Stops Responding

查看:36
本文介绍了VB6 应用程序停止响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用 VB6 编写的程序,它读取一个长文本文件并执行一个很长的操作.我也实现了进度条,但我的问题是,在我的程序说无响应"之后,任务完成后它又开始响应.

I Have a program written in VB6 that reads a long text file and performs a very long operation. I have also implemented progress bar, but my problem is that, after while my program says "Not responding" and it starts responding again when the task is completed.

如何消除这个无响应"问题?

How do I remove this 'Not responding' problem?

推荐答案

Windows/Explorer 会将进程更改为无响应"状态,因为它在没有处理任何消息的情况下持续时间过长.在 VB6 中,当运行一长段代码而不调用 DoEvents 时会发生这种情况.

Windows/Explorer will change a process to the "Not responding" state when it goes too long without processing any messages. In VB6, this will happen when running a long section of code without calling DoEvents.

不幸的是,VB6 不能轻松地执行多线程,因此您最好的选择是在操作期间定期调用 DoEvents.理想情况下,这应该是在更新进度条位置之后.

Unfortunately, VB6 doesn't easily do multiple threads so you're best option is to periodically call DoEvents during the operation. Ideally, this would be just after updating the progress bar position.

执行此操作时,您需要小心防止重入.通过在长时间操作开始时禁用控件并在完成时重新启用它们,这很容易.如果您想让它们取消,您将需要使用您在取消按钮点击事件中设置的布尔值并检查 after 调用 DoEvents.

When doing this, you will need to be careful to protect against re-entrancy. This is easy enough by disabling the controls when the long operation starts and re enabling them when it's finished. If you want to let them cancel, you will need to use a boolean value that you set in the cancel button click event and check after calling DoEvents.

这篇关于VB6 应用程序停止响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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