How to change the value of the Settings.settings parameter

I have a simple console application that runs daily (called by the Windows Task Scheduler) and depends on the value that increases every time the application starts. To save this value, I decided to use the Settings.Settings file.

So, I have an integer value called RunNumber with a user area that increments every time the application ends:

Properties.Settings.Default.RunNumber++;
Properties.Settings.Default.Save();

Part of the reason I chose this is because the value is also placed in the app.config file:

<setting name="RunNumber" serializeAs="String">
    <value>0</value>
</setting>

This means that if the RunNumber should suddenly increase, it can simply be changed in app.config:

<setting name="RunNumber" serializeAs="String">
    <value>10</value>
</setting>

, , RunNumber, , app.config( 10). , , , , , 1 10, .

RunNumber :

Properties.Settings.Default.RunNumber

RunNumber ? , , app.config , .

+5
4

, app.config, , , . user.config .

, user.config, - , app.config, .

Windows 7 Windows Forms Example.Settings.CustomClass user.config:

C:\Users\[user]\AppData\Local\Microsoft\Example.Settings.CustomCl_Url_3qoqzcgn1lbyw2zx3oz1o3rsw2anyjsn\1.0.0.0
+6

, RunNumber

, App.config, Users\<user>\AppData\....

( ), .

+2

, app.config, , reset , , myapp.exe /setcount=123.

, , , .

+1

Just use Reload () before accessing your class Settings. You can change the generated class Settingsto call Reloadeach time a specific property accesses it.

0
source

All Articles