It appears that System.Diagnostics.ProcessThread has TotalProcessorTime, but that ProcessThread is for system threads, so how do I get the ProcessThread for the System.Threading.Thread.CurrentThread? Thanks.
Asked
Active
Viewed 46 times
0
-
1What is it you are really trying to do? Managed threads will be backed by system threads. There are no 'green threads' like in java, even if tasks does something similar. – JonasH Jun 14 '23 at 06:19
-
TL;DR: **You can't** and you shouldn't: this is because .NET's Managed Threads do not map cleanly to OS threads: a given single `ProcessThread` may actually correspond to multiple `ManagedThreadId` values, so the `TotalProcessorTime` value is not a meaningful value in .NET. See here: https://stackoverflow.com/questions/1679243/getting-the-thread-id-from-a-thread – Dai Jun 14 '23 at 07:51
-
Hi @JonasH, I'm adding a feature to a service I offer, and I want to charge customers for their CPU usage of that feature. – uncaged Jun 14 '23 at 20:05
-
Hi @Dai, my customers will be able to submit requests to use a new feature of my service, and depending on their requests, might take milliseconds or might take seconds. Some customers might not use the feature, and others might use it heavily. I want to charge fairly for the load customers put on my processors. Any suggestions? – uncaged Jun 14 '23 at 20:13
-
1@uncaged Why can’t you just use wall-clock time measured with a StopWatch? It sounds to me like you’re trying to be _too smart_ here. Companies haven’t billed users by hardware time since we stopped using timeshare systems in the 1980s… – Dai Jun 14 '23 at 20:36