5

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?

Deanna
  • 23,876
  • 7
  • 71
  • 156
Vinay K
  • 463
  • 6
  • 18
  • 1
    Welcome to StackOverflow. You may want to read the FAQ and related pages about the [etiquette](http://stackoverflow.com/faq#etiquette), and try not to SHOUT or use bold text needlessly. – Deanna Jun 22 '12 at 13:45
  • 1
    You might be interested in the related questions [cancelling a long-running process in Vb6](http://stackoverflow.com/questions/155517/cancelling-a-long-running-process-in-vb6-0-without-doevents) and [using threads in VB6](http://stackoverflow.com/questions/383162/to-use-thread-in-programming-in-vb6) and [making a kill event for a Vb6 app](http://stackoverflow.com/questions/727386/making-a-c-sharp-kill-event-for-a-vb6-app). The titles might not seem related, but the answers will be useful for you. They explain some different ways that you can do background processing in VB6 – MarkJ Jun 22 '12 at 15:04

2 Answers2

7

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.

Deanna
  • 23,876
  • 7
  • 71
  • 156
  • +1 As discussed [here](http://stackoverflow.com/questions/155517/cancelling-a-long-running-process-in-vb6-0-without-doevents) – MarkJ Jun 22 '12 at 15:05
1

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

Community
  • 1
  • 1
Alvin Wong
  • 12,210
  • 5
  • 51
  • 77