Timer low CPU

Share your advanced PureBasic knowledge/code with the community.
Learner
User
User
Posts: 15
Joined: Tue Dec 14, 2004 1:32 am
Location: Australia

Timer low CPU

Post by Learner »

Code: Select all

;--------------------
; Access PBOSL Timer from any code with Low CPU overhead
;  up to 1 ms - Learner
;--------------------
Global ObEvent.l

Procedure mytimer1()
  If Not pulseEvent_(ObEvent) ;Sets Event to Signaled then Reset to off
    Debug "darn "+ Str(ObEvent)
  EndIf
  
EndProcedure

ObEvent = CreateEvent_(#Null,#False,#False,#Null)

StartTimer(0, 10, @mytimer1());10 ms timer
Repeat
  MeasureHiResIntervalStart();meassure Speed 
  WaitForSingleObject_(ObEvent, #INFINITE);This reduces loop processor load
  Debug MeasureHiResIntervalStop();in seconds
  Delay(10) ;can leave this out
  If GetAsyncKeyState_(#VK_RBUTTON) ;end if right button pressed
    EndTimer(0)
    End
  EndIf
ForEver