Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2006 Oct : pause thread ~5msec

www.cryer.info
Managed Newsgroup Archive

pause thread ~5msec

Subject:pause thread ~5msec
Posted by:"Szakály Balázs" (szakal..@freemail.hu)
Date:25 Oct 2006 22:42:57

Hi!

I must wait ~5msec (+-1msec) on a communication thread. (High priority class, timectitical priority thread)
I can do it with QueryPerformanceFrequency and QueryPerformanceCounter on a While loop:

    LEnd := calculate end counter
    while True do
    begin
      QueryPerformanceCounter(LNow);
      if LNow>=LEnd then
        break;
      ???Sleep??? ~1msec - how?
    end;

This code works correctly without sleep, but cause high cpu usage.
Sleep(0) does nothing = high cpu usage.
Sleep(1) = ~10-20msec wait.

Is there any trick to pause thread (only this thread) <=1msec on windows?


Balázs Szakály
szakalyb@infolab.hu

--

Replies:

www.cryer.info
Managed Newsgroup Archive