views:

413

answers:

1

Hi, I wonder if it is possible in a Compact Framework application to prevent the garbage collector to unconditionally stop at least one of the threads, or if it is possible 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 advices against doing it...

Thank you in advance,

+3  A: 

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.

Sunny