troubleshooting Question

How to keep thread from hogging all CPU time

Avatar of lajko
lajko asked on
Delphi
9 Comments1 Solution502 ViewsLast Modified:
I have a thread which does effect transitions between 2 images. It is for kiosks where they cycle through advertising "slides" when there is no user activity. It runs 2 separate monitors from the same program, each displaying their own set of slides. Now that I am adding video into the sequences, I notice some effects hog the cpu time and the video stalls briefly (although the sound is not interrupted) while the effect is running.

The core of the effect code is...
    repeat
        do next step in effect
    until terminated or effect_is_finished

how can I get it to release cpu time and not use it all so the video or otherthings do not briefly stall?

Code was written by employee not with us, but we know how the uncommecnted code works. What we need is:

1. First step, due to not much time available for this item, is just to get it to not hog all cpu time during an effect. A simple "application.processmessages" doesn't seem to do it. I guess because the video running is not issuing any messages to be processed.

2. The second step will be to have this core of the effect do a step in the effect only once evert 30th to 50th of a second. After all, there is no need to update the image on the screen for each and every step of a slide in or other effect, which could be up to 800 steps (screen size 800x600). It would be better to update the progress of the effect in larger chunks at the same rate as NTSC video - 30 times a second (or 60 if you count interlacing) - which would leave plenty of time for video and other things to run. So how would we implement a timer in the above code to do this?

It should be easy for someone familiar with writing threads. This is the only thread code in the kiosk project and as I said before, the employee that wrote the thread isn't with us and the rest of us have never had to get into the writing of threads.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 9 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros