0

I created settings in my winforms app like this: link

You can see I have timer interval value there. With the goal that inside timer here:

{
    // Inside timer tick handler
    ....
      finally
                {
                    timer1.Stop();
                    int tinterval = Properties.Settings.Default.TimerInterval;
                    HelperMethods.AppendToLogFile(tinterval.ToString(), LogType.Information);

                    timer1.Interval = tinterval;
                    timer1.Start();
                }
}

I want to change interval value of timer on runtime.

But when I launch the application even if I change the interval inside the app.config file (opened from windows explorer), still old value is being read inside the timer above. What am I doing wrong?

EDIT: Actually this doesn't even work, if I close my application, and start it again (i.e. restart my application). It still reads old values from app.config (not the ones I entered after application was shutdown and before application was opened). What am I getting wrong?

PS. The culprit maybe here, please see - It always reads the old value 1500, instead of 2000. You can see how VS is saying (after I closed and reopened project) that settings file still has old value, what is going on here?

  • Do you mean you want to re-read the app.config at runtime? http://stackoverflow.com/questions/6335931/save-and-reload-app-configapplicationsettings-at-runtime – CodeCaster Jul 08 '15 at 10:27
  • @CodeCaster: Yes at run time. I would appreciate if you can provide sample code in my case - where to put that code. Assuming I want to read values of `TimerInterval` and `OracleConnectionString` at run time (user will just manually change the app.config file anytime) –  Jul 08 '15 at 10:31
  • @CodeCaster: This does not work - even when I closed my application and started it from beginning, new values - which I input in app.config file, are not being read. ?! –  Jul 08 '15 at 10:40
  • 1
    Are you editing the app.config in your bin directory? That gets overwritten every build... – CodeCaster Jul 08 '15 at 10:41
  • @CodeCaster: No it is here: C:\Users\gr\Documents\Visual Studio 2012\Projects\Gateway\Gateway; please see also my update to the question –  Jul 08 '15 at 10:42
  • @CodeCaster: please see my update –  Jul 08 '15 at 10:46
  • @CodeCaster: There is no app.config in my bin directory. Do you have any other advice, I am getting confused –  Jul 08 '15 at 11:14
  • Write things to text file and read from it if applicable to your situation. Don't use app.config. Configs are for different purpose. – Raj Karri Jul 08 '15 at 11:21

2 Answers2

2

Assuming you have the default settings applied, the configuration file for Settings is likely saved in the user directory, not the application directory. Thus you're editing the wrong file. That's because the Scope value is set to User in the settings editor in Visual Studio.

Try finding your application's configuration in AppData (usually Local\YourCorporation\Application_version or something like that).

Luaan
  • 62,244
  • 7
  • 97
  • 116
0

Part of the answer is here Changes in App.config do not reflect after restarting the application

But seeing changes of config file at runtime, I didn't solve and ignoring at this stage.

Community
  • 1
  • 1