Search code examples
c#.netgarbage-collectionclr

Does GC stop all app threads in .NET?


I was reading and article about optimizing .Net app performance. The authors state

it shows what the main thread did during all those GCs. Most of the time (97.3%) it was Waiting. This means that GC took place on some other thread (obviously on the FileProcessing thread) and the main thread had to wait until the GCs were finished.

As far as I know .Net GC is stop-the-world collector. Thus, if your Main thread is waiting, that means ALL other threads must be waiting as well. Except GC thread itself.

Is the article outdated or I'm getting it wrong?


Solution

  • The reason is misunderstanding between Background GC which happens in a separate thread and Blocking GC which runs on the same thread as the one who triggered GC.

    https://jetbrains.com/help/profiler/CLR_Activity.html