GC start and stop events
c#, events, garbage-collection
Solution
This is what the Profiling API is for. See ICorProfilerCallback2::GarbageCollectionStarted and GarbageCollectionFinished.
As this is a profiler, it obviously isn't suitable for routine use on a production system. But it sounds like you're primarily interested in this for diagnostic purposes anyway. So it might be worth checking whether one of the commercial profilers offers this facility already, or whether the perfmon counters would suffice -- writing your own profiler could be an awfully heavyweight solution!
Problem
Isn't it possible to get an event when the GC begins? I want to time each individual GC so I can see if pauses in my server are due to GC or something else. The GC pauses all .NET threads while running, right? (Except the thread that it runs on, of course). How about unmanaged threads? Thanks!