I wrote a program that is highly dependent on threads. In addition, you need to measure the total time spent by each thread, as well as the execution time (kernel time plus user time).
There can be an arbitrary number of threads, and many can be started immediately. It depends on user activity. I need them to start as quickly as possible, so using something that has some overhead, such as WMI / Performance Monitor, to measure thread time, is not ideal.
I'm currently using GetThreadTimes, as shown in this article: http://www.codeproject.com/KB/dotnet/ExecutionStopwatch.aspx
My question is simple: I understand that .NET threads may not match each other individually with system threads (although in all my testing so far it seems to have been one to one). In this case, if .NET decides to put two or more of my threads into the same system thread, am I getting weird results from my time code? If so (or even if not), is there another way to measure the kernel and user time of a .NET thread?
source share