Question

Is it possible in a Compact Framework application to prevent the garbage collector from unconditionally stopping at least one of the threads, or to block GC collects at least in some portions of the code?

I think it has to deal with setting real time priorities, but I found a lot of advice against doing it.

Was it helpful?

Solution

The GC needs to freeze all threads in order to inspect all objects. How could it do its job, if some thread is running and is modifying/creating an object?

Better don't do it.

What you can do thogh, is to invoke GC.Collect() and GC.WaitForPendingFinalizers() before you enter in a state where you do not want to be interrupted. This will give you some time.

OTHER TIPS

Unmanaged code is not allowed to access unpinned managed objects, but it will run without blocking during garbage collection. If you have certain routines that must keep running during garbage-collection, and they don't require access to unpinned managed objects, you could write those routines in unmanaged code and the GC wouldn't affect them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top