How to enable CLR Server GC?

This is one of the mostly asked questions about CLR GC.

CLR's GC has two modes: Server GC and WorkStation GC. The difference is discussed briefly in Gregor Noriski's MSDN article about writing high performance managed application(https://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/highperfmanagedapps.asp).

In .Net framework 1.0 and 1.1, the only supported way to enable server GC is going through CLR's hosting API. Steven Pratschner provided a sample in a newsgroup post: https://groups.google.com/groups?hl=en&lr=&ie=UTF-8&frame=right&th=8d37b7b7c04b7609&seekm=O6jAptPPDHA.2284%40cpmsftngxa06.phx.gbl#link2

In Whidbey (.Net framework 2.0) and 1.1 Service Pack 1, CLR introduces a config file option to enable server GC. The syntax is following:

<Configuration>
    <runtime>
        <gcServer enabled=“true“ />
    </runtime>
</Configuration>

This can be put in app.config or machine.config. App.config is preferred so that it won't affect all the applications on the machine.

In .Net framework 1.1 you can check if Server GC is enabled by checking whether mscorwks.dll or mscorsvr.dll is loaded. If mscorsvr.dll is loaded, then Server GC is enabled.

In Whidbey mscorsvr.dll is merged into mscorwks.dll, so the above technique will not work. Instead, System.Environment.IsServerGC should be used to check against Server GC.

This config file should work with Whidbey Beta1 and .Net framework 1.1 SP1 Technical Preview. Both are available now.