3

Could someone please explain application and user settings, and their differences to me? I've got a C# application that only ONE person will use. There are preferences the user can set within the program, and I implemented these preferences with user-scoped settings. I was under the impression user-scoped settings would be able to be read and written at runtime, which they are. But they are not persisting. Once the application is closed and reopened, poof, there go all the user's settings.

Application settings seem to be a better fit for what I'm doing, except they can't be manipulated at runtime.

So...

Question #1: Are user-scoped settings suppose to persist?

Question #2: Is the difference between user and application scope the fact that application cannot be changed at runtime, but user can?

Question #3: If I can't use settings, or shouldn't in this case, what would alternative suggestions for saving preferences be?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
CODe
  • 2,253
  • 6
  • 36
  • 65

1 Answers1

2

There's some good information here.

  1. Yes. Make sure you're calling the Save() function on them at some point! Usually with Settings.Default.Save().
  2. Yes, but no. I believe that technically you can change and persist application settings at runtime, but not really because most deployment mechanisms prevent this because your installation folder should be read only.
  3. N/A. Use the settings! You're on the right track. If you find you need to persist loads of information then you might need to look at richer data stores - e.g. XML, SQL, SQL-CE, etc.
Reddog
  • 15,219
  • 3
  • 51
  • 63
  • Wasn't calling save. Bah! Can I save before the application closes or do I have to save when I make a change? Maybe an onClosing event save the settings? – CODe Dec 23 '10 at 17:28
  • I'd save OnChange, just in case your app crashes. Unlike VS.NET not saving my settings when it crashes cough cough. – mxmissile Dec 23 '10 at 17:32
  • CODe - Yes, you can save settings using the Form's **Closing** Event. And don't forget to **save** those settings! Something like **Properties.Settings.Default.Save();** should do the trick. –  Dec 23 '10 at 17:33
  • I tend to wrap my user settings as (static) properties on the class that they are relevant to. That way in the setter it can call Save immediately but also impose validation if need be. – Reddog Dec 23 '10 at 17:37