Link to home
Start Free TrialLog in
Avatar of Torus
Torus

asked on

How to move or resize the form during intensive job?

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?

Thanks

ASKER CERTIFIED SOLUTION
Avatar of Mirkwood
Mirkwood

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chabaud
chabaud

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.
Avatar of Torus

ASKER

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.



Avatar of Torus

ASKER

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?

Thanks
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 .
Avatar of Torus

ASKER

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

ASKER

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).
Avatar of Torus

ASKER

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.
Avatar of Torus

ASKER

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.

CAUSE

 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.
Avatar of Torus

ASKER

The article ID is Q198607. For more information, you can go to see it.