An unexpected result while using Sleep()

 

Hello everyone

I need to measure the  most  possible precis time delay of some operations.

While I was working on it, I had some unexpected result.

void OnTick()
  {
   uint Timer_Start = GetTickCount();
   
 
   uint  Delay = GetTickCount() - Timer_Start;
   
   Comment(Delay); 

 
  }

It comments 0 on the chart. How is it possible?

Then I added a sleep function and it got worse.

void OnTick()
  {
  uint Timer_Start = GetTickCount();
    Sleep(1000); 
   uint  Delay = GetTickCount() - Timer_Start;
   Comment(Delay);
//---
  }

The result is mostly 998 and 999 . some other values are also shown but it seems all of them are less than 1000.

How is it possible? 

I think I used those functions just like what the documentation says.

GetTickCount - Common Functions - MQL4 Reference
GetTickCount - Common Functions - MQL4 Reference
  • docs.mql4.com
Counter is limited by the restrictions of the system timer. Time is stored as an unsigned integer, so it's overfilled every 49.7 days if a computer works uninterruptedly.
 
Reza nasimi: How is it possible?
Because the Windows system timer has always been (IIRC) 16 ms. Therefor Sleep is approximate.
 
William Roeder:
Because the Windows system timer has always been (IIRC) 16 ms. Therefor Sleep is approximate.

Thanks  William Roeder

Reason: