Why DisableBackgroundTasks?

Somebody please explain to me why you should disable background tasks and why you should enable it. I do not really understand the documentation. And I do not have a very good knowledge of threads. If I am right, threads are ticked through without missing ticks and the timer can miss some ticks so the CPU can act on other threads/timers. Or something like that.

Thanks in advance

We use it to ensure a block of code, usually in a loop, executes without delay and without any other code in our app executing. Sometimes it’s about performance but it is usually about having all of that code execute inline.

If you don’t use threads, you don’t need DisableBackgroundTasks.

well, still without threads on every loop boundary, the runtime will check if it’s time to switch to another thread.
So loops can be faster with DisableBackgroundTasks.

[code] #pragma DisableBackgroundTasks

dim m as Double = Microseconds

dim n as integer
for i as integer = 1 to 10000000
n = n + 1
next

dim t as Double = Microseconds

MsgBox str((t-m)/1000000.0, “0.00”)+" seconds"[/code]

with DisableBackgroundTasks: 0.48 seconds. Without 0.78 seconds.