title: How to know if a gen full garbage collection has been triggered between two checkpoints?
body: <p>I am doing analysis on the time spend in a critical section of code.</p>
  <pre><code>//Take a timestamp before
  var before = DateTime.UtcNow;
  
  DoCriticalMethod();
  
  //Take a timestamp after
  var after = DateTime.UtcNow;
  </code></pre>
  <p>And sometime I have some values clearly higher than others.</p>
  <p>I suspect that it is Garbage collection, so I want to correlate the high values with the fact that a Garbage collection occured during the process.</p>
  <p>I tried this so far :
  I take the counter before :</p>
  <pre><code>//Take the number before
  int gc2CountBefore = GC.CollectionCount(2);
  
  ...
  
  //Take the number after
  bool hasgc2occured = (GC.CollectionCount(2) - gc2CountBefore) != 0;
  </code></pre>
  <p>Am I doing it in the good way?</p>