ConcurrentDictionary.Values
requires a lock in order to retrieve the data from the dictionary while looping directly through the dictionary does not use any locks, but you get the KeyValuePair
itself so you will have to call .Value
on each result.
Running VSDiagnostics
CPU usage tool, part of the insights it recommended for my desktop application was that the call to .Values
was appearing too often. Specifically the message was
So I’m wondering, if I replace it with a loop through the KeyValuePair
and call .Value
will it actually improve the CPU usage or will it just hide the issue as now it will not be a single call that takes all up the time, but multiple small ones taking up the same amount of time, but since all of them will be smaller, it won’t be flaggable?
1