troubleshooting Question

Time critical app stops when any window is moved...

Avatar of passpics
passpics asked on
Delphi
7 Comments1 Solution223 ViewsLast Modified:
I am writing an application that needs an accurate and continous clock 'pulse' every 40mS or less: basically it's sort of like a MIDI music sequencer, but for another purpose. Everything works fine - I've done a custom component that fires off a NotifyEvent at nice, regular intervals, and I can display that as a time. Here's the beef of my timer component:

procedure TTimecode.RunClock;
var
     Interval : single;
     fq, ct : int64;
     MIDICount : integer;
begin
     Interval := FRameRate / 1000;
     MIDICount := 0;
     while Enabled do    //Keep looping
     begin
          QueryPerformanceFrequency(fq);     //Get the frequency
          Repeat
               QueryPerformanceCounter(ct);  //Get the current count
          until (ct - OldCounter) / fq >= Interval;  //Time in miliseconds since last loop
          OldCounter := ct;        //Keep this for next time around
          If assigned(OnMIDIFrame) then OnMIDIFrame(self);
          inc(MIDICount);
          If MIDICount = 5 then MIDICount := 1;
          If MIDICount = 1 then
             If assigned(OnTCFrame) then OnTCFrame(self);
          sleep(1);                //Reduces processor load
     end;
end;

In my main app code, this is used as follows:

procedure TfrmMain.MasterClockTCFrame(Sender: TObject);  //Called once every full frame
var
     n : integer;
begin
     //Update clocks for any timelines running on internal sync
     For n := 0 to length(TL) - 1 do
          If TL[n].Sync = syInt then TL[n].Time := TL[n].Time + mspf;
     frmTimeline.UpdateClock;   //Update the timeline display
end;

TL is a dynamically created array of records, with Time as a field. UpdateClock is a little procedure that simply shows the time in an edit control. mspf is the time to increment in miliseconds for each event (each item in the TL array can have a different time).

Now here's the problem: if I click on any child window's caption bar, the clock stops. I don't mean the form's paint does not update, I mean it's like the whole thread stops, until I release the mouse. TL[x].Time is not updated until I release the mouse. My app is time critical, so this is clearly not good! I tried setting my apps thread priority to REALTIME_PRIORITY_CLASS, but that did not help. Any ideas? I need the clock to always keep counting, even if the user moves a window around.

ASKER CERTIFIED SOLUTION
flasht

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 7 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 7 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004