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 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
.
You can call DoEvents
in your long operation but be careful as it has various caveats associated with it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With