Your application is about to enter a block of code that you don’t use; you want to interrupt a possible garbage collection ....
A very suspicious argument (which, however, is used a lot).
Windows is not an operating system. Your code (Thread / Process) can always be a proactive OS scheduler. You do not have guaranteed access to the CPU.
So, it boils down to: how does the time for the GC-run compare with the time interval (~ 20 ms)?
There is very little data about this hard data, I searched for them several times.
From my own observation (very informal), the gen-0 collection is <40 ms, usually much less. Full gen-2 can work up to ~ 100 ms, possibly more.
Thus, the “risk” of interrupting a GC is of the same order of magnitude as that of another process. And you cannot control the latter.
Henk holterman
source share