Re:OnTimer priority
"Øyvind Hansen" <
oyvind@scantrol.no>wrote in message
Quote
I my control system i am using OnTimer() to run control routines as serial
communication, calculations and control routines. The code runing on timer
is big alredy and it is growing....causing bad PC performance. I think i
am
wrong in using timer for this task as moving dialogs around the screen
will
stop or delay the timer event. Appreciate if someone could tell me the
best
way of preventing userinterface operation from interfering with
performance
of my background tasks, and for big background tasks not to freeze
userinterface.
At the end of the day:
(1) you can't burn more CPU cycles in a given time than your processor is
capable of delivering.
(2) Windows is not a real-time operating system
so you're on a loser; you can't "solve" this type of problem, you can only
make it "better", but if you're lucky "better" may turn out to be "good
enough".
Certainly you should run your non-GUI routines in another thread to remove
the absolute interdependence that you are currently seeing. However CPU
cycles are still CPU cycles, and if you give the new thread higher priority
then the GUI might get a bit less responsive, and if you give the new thread
lower priority then you might not get the work done in a cycle if someone
starts playing with the GUI.
I did once have a thread doing some machine control switch itself to real
time priority for the critical part of its cycle, which worked - but of
course the GUI froze completely for every other half second (or whatever it
was) and basically I was lucky (with things like the operating system still
being able to write the results to disk) as Windows is not designed to be
used like that.
--
Tim Ward
Brett Ward Limited -
www.brettward.co.uk
-