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?

DoEvents is really for Console Applications so you don't need need it, nor does it really do anything in desktop applications. Threads in RB apps are cooperative meaning that it will play nice with other threads so the timing may or may not be (probably not) be very accurate or reliable.

When DoEvents is called from a Thread, it yields to the main thread so that the Event Loop can be run. This necessarily slows down any code that calls DoEvents, especially within a loop where the delay is repeated in each iteration.

Your timing code is not very accurate and is susceptible to "drift". Instead of adding LoopSpeed to a counter, compare the total elapsed time. The code that adds LoopSpeed to TimeCounter could execute after 100ms, or 120ms, or more, allowing the total actual time to drift longer and longer.