I was recently showing someone the new ETW features in .NET especially the GC Event notification and I was asked if we can get this using Windbg.

So here is the sample code for the GC Collection

[sourcecode language=”csharp”]

namespace GCStartStop

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

button1.Click += (s, b) => GC.Collect(2);

button1.Click += (s, b) => GC.Collect(1);

}

}

}

[/sourcecode]

The goal is set to a break-point only when the collection count is 2. Here is a bp script for doing this.

[sourcecode]

bp clr!WKS::GCHeap::SuspendEE “.if (dwo(clr!WKS::GCHeap::GcCondemnedGeneration)==2) {.echo start of gen 2;g} .else {gc}”

[/sourcecode]

The same thing can be done for clr!WKS::GCHeap::RestartEE.

When showing this to someone I was asked what does “EE” acronym in “SuspendedEE” ?  “EE” is  Execution Engine.