We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now


How to move or resize the form during intensive job?

Torus asked
Medium Priority
Last Modified: 2010-05-03
I wrote a program that should do some intensive job, e.g read a large file and then analyse the data. I have added a
Doevents in the function that does the intensive job.  
It is no problem if I move the form after the program enters
the function. However, if I move the form and once the function starts executing, the form is frozen until the function finishes. It seems the Doevents is no use at this situation. Why? How can I solve this problem?


Watch Question

Unlock this solution and get a sample of our free trial.
(No credit card required)

I don't understand your problem.

Are you sure you call doEvents regularly in your function.
The DoEvents statement allow the windows messages to be processed by your appli or other appli including the paint message.



Hi chabaud, I am sure that I add the Doevents in the loop on the function that does intensive job. My problem is, for Examples, if the function that does the intensive job called  "TEST".

If now the program is executing the "TEST" function, I can move the form everywhere on the screen.  However, if the program now run the other code before calling "TEST"(the code before is not intensive), I can still move the form, but while I moved it and once the "TEST" is called, the form is frozen at once and I can't move it anymore until the "TEST" completes.


Mirkwood, if I want the function that used to create the thread has more than 1 Parameter or for example, return the result from a complex calculation. Can I do that since I just see that the createthread just allow to pass one argument?


You can pass a instance of a struct as parameter and some of these values can be for meant as output and some for input.
You can also pass an instance of a class .


SOrry, one more question. Is it possible the thread notifies me when it finishes the job.


Mirkwood, I tested the program in the design environment and that's no problem. However, once I compiled it to exe and run it today every time, Dr.Watson appears

Hmm, it works ok with me. Have you also tried the other MSJ article I recommended. Does that crash to. Are you using win95, btw?
Maybe we should just go for the timer solution. That one is easier (altough not as good).


I am using NT, VB6. I will test the other later. But can it notifies me when finished?

Sure, you execute a function. At the end of this function you can do anything you want: Raise an event of a class or call another function. The correct way to do it ofcourse is with semafoors. No example available though.


Mirkwood, I found a reference from microsoft article about CreateThread

When running your Visual Basic application, you may encounter an error similar to the following:

The instruction at 0x660bd3b1 referenced memory at 0x0000009c. The
memory could not be written.

This error may occur immediately following a declared API function call within a Visual Basic callback function.


 When the error occurs, the callback function is called by a thread that was not created by Visual Basic.

For instance, certain API calls such as CreateThread() and RegisterServiceCtrlHandler() will create an additional thread before invoking the callback function that was
previously setup by using the AddressOf operator. Although the same code may have worked in previous versions of Visual Basic, calling API's of this nature are currently
unsupported in Visual Basic.

Furthermore, additional care must be taken with regards to what code can be executed within the callback function. Any use of the following within the callback function may
cause undesirable results:

          File I/O.
          Error handling.
          Fixed size arrays.
          Set statements.
          COM method calls that return HRESULTs (such as any Visual Basic ActiveX           object).
          Declare calls.
          Global objects such as the Application object.
          Most of the Visual Basic run-time files.


The article ID is Q198607. For more information, you can go to see it.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.