VB6 Application Stops Responding

只愿长相守 提交于 2019-12-12 11:14:29

问题


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?


回答1:


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.

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.

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.




回答2:


You can call DoEvents in your long operation but be careful as it has various caveats associated with it.



来源:https://stackoverflow.com/questions/11156978/vb6-application-stops-responding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!