2

I thought of reading Properties.Settings into fields and then using those fields for performance reasons, because Properties.Settings uses reflection However, maybe those values are cached therefore there's no point in that.

So, are Properties.Settings cached?

ispiro
  • 26,556
  • 38
  • 136
  • 291
  • Reflection is also cached by the way. – DavidG Jun 27 '19 at 13:35
  • @DavidG Do you have a source for that? If so, that's the answer. – ispiro Jun 27 '19 at 13:36
  • I wouldn't say it's an answer, just an interesting point. My real point though, would be how much of a performance benefit do you get from caching these values anyway? Is it worth the time you are spending on it? I usually refer people to this: https://ericlippert.com/2012/12/17/performance-rant/ – DavidG Jun 27 '19 at 13:40
  • @DavidG According to [Marc Gravell](https://stackoverflow.com/questions/5669272/how-to-cache-reflection-in-c-sharp#comment6470508_5669423) in certain cases "effective caching of reflection can make all the difference.". – ispiro Jun 27 '19 at 13:41
  • 3
    Yes, it can help if you are doing a LOT of reflection. But if you call these sparingly, it will make no difference at all and you have just wasted time worrying about it. – DavidG Jun 27 '19 at 13:42
  • Also bear in mind that comment was written 8 years ago, things may have improved since then. – DavidG Jun 27 '19 at 13:43

1 Answers1

4

Remarks section of ApplicationSettingsBase.Reload method documentation refers caching.

The Reload method clears the currently cached property values, causing a reload of these values from persistent storage when they are subsequently accessed. This method performs the following actions:

  • It clears the currently cached properties by clearing the collection represented by the PropertyValues property.
  • It raises the PropertyChanged event for every member of the Properties collection.

Reload contrasts with Reset in that the former will load the last set of saved application settings values, whereas the latter will load the saved default values.

https://learn.microsoft.com/en-us/dotnet/api/system.configuration.applicationsettingsbase.reload?view=netframework-4.8

Mustafa Gursel
  • 782
  • 1
  • 7
  • 16