My thread has this code:
dim LoopSpeed = 100 '(ms)
dim UDPThreadRequestStop as boolean
Dim Now as double
dim TimeCounter as Uint32
UDPThreadRequestStop = false
Now = Microseconds
do until UDPThreadRequestStop =true
app.doevents
MainSemaphore.Signal
if Microseconds-Now >= (LoopSpeed * 1000) then
Now = Microseconds
'Code to execute every 100ms
if Timecounter >= 10000 then UDPThreadRequestStop = true 'Exit Loop
'Other code....... executed in 8 ms
TimeCounter = TimeCounter + LoopSpeed
end if
MainSemaphore.release
loop
The thread ends after 100 loops (100ms * 100 = 10000ms) but it ends only after 11 or 12 seconds (not 10 seconds).
If I remove the code "app.doevents", the thread works perfectly but the CPU Usage is 30%.
There is a solution to this problem?
Why does "app.doevents" need a lot of CPU time?
Note: The project contains only a thread and a window.