How to count context switching programmatically?
2 answers
There is a performance counter that does your job. All you have to do is read its value. You can find a description of how to do this interactively here , but performance counters can also be used using their API.
+7
source to share
The problem with counting your own context switches is that you can switch contexts while counting them! Worse, your own counting code subtracts from the amount of time your own process has, so you can execute less in a single loop of context.
As On Friend (+1) says, use a performance counter instead that counts contexts at a higher level.
+2
source to share