Priority in real time process

I hav develop a program in VBA environment, to get data through serial comm.
In the program i use the timer (can be set from 0.5s -> ) to get the data. The process of getting data take around 0.2s.

I face 2 problem:

1)  The Timer is not given the highest priority in the program. When an interupt (eg. open a data file) occur, it will then go on with the interupt. This will then stop the process in timer for a while. This will miss out some real time data.

2)  When open others application/program in O/S (Win2000), the program will also be interupted. Different with (1) is that the timer will run but overflow in memory happen to be.

How to set the timer to highest priority in program and memory priority?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Point 2:

Dont you mean a STACK overflow?

This happens when you start to process your getdata() while you are still in it..

You need to make sure that your getdata Function wont start while it is running. This can be acomplished with a static variable inside the function (isRunning) - just set it to true while you process your data and then set it back to false when you leave your function...

Only process data when it is false...

Another thing you might consider is to split up your processes... Create one for gathering data , one for processing and one for controlling the other 2.. So they wont run into each other and cause themself to miss something....

P.s: 0.5 s is no realtime ;)
kenkiiroAuthor Commented:
Thanks for reply.
What actually u mean by STACK overflow?

what u say is good idea, but if i want the getdata() to run at priority process and its run all the time once the program start (eg. getting data every 0.2s), so in between the 0.2s can do other process after doing the getdata().

But problem is that can we run the "process 2" half way and continue running it after the "process 1"(getdata())?
Because the getdata() is time consuming, and the process to most of the time can't be finish between 0.2s (eg. saving a large file to harddisk)

thanks for the proffesional advice!!  :)
It would probably be much more advisable to write a program like this in a truly multithreaded environment such as Visual C++ so that you can spawn a seperate thread to read the serial COMM data and in the background perform any file IO you need to take care of.  Plus, you'll have control over your thread priority.

It is possible to call kernel32's CreateThread(...) within a VB6 program but it's really not recommended.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
Moderator, my recommended disposition is:

    Accept HarmnKardn's comment(s) as an answer.

DanRollins -- EE database cleanup volunteer
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.