troubleshooting Question

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

Avatar of passpics
passpics asked on
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;
     Interval : single;
     fq, ct : int64;
     MIDICount : integer;
     Interval := FRameRate / 1000;
     MIDICount := 0;
     while Enabled do    //Keep looping
          QueryPerformanceFrequency(fq);     //Get the frequency
               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);
          If MIDICount = 5 then MIDICount := 1;
          If MIDICount = 1 then
             If assigned(OnTCFrame) then OnTCFrame(self);
          sleep(1);                //Reduces processor load

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

procedure TfrmMain.MasterClockTCFrame(Sender: TObject);  //Called once every full frame
     n : integer;
     //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

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.

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 7 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 7 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