title: C# Windows Service Timer app config change in runtime
body: <p>I'm making some Windows Services in c# and i need to read some variables from a config file like files and paths. I also have a variable that controls (it should) the timer interval. The problem is, every time a change data in the config file, that data is not fetched and, for example, if i change the file name i get an error saying that the file  does not exist (and i checked the name and the path) or if i change the time interval nothing happens. Can someone help me please?</p>
  
  <pre><code>System.Timers.Timer timer;
      CallWebServices call;
      int time;
  
      public Planview_SEB_Pervasive()
      {
          InitializeComponent();
      }
  
      protected override void OnStart(string[] args)
      {
          call = new CallWebServices();
          startPervasive();
      }
  
      protected override void OnStop()
      {
          timer.Enabled = false;
          call.InsertLog("PV/S&amp;B Win Service", "Serviço parado", "");
      }
  
      private void startPervasive()
      {
          try
          {
              try
              {
                  //Vai buscar o tempo ao app.config
                  time = Convert.ToInt32(ConfigurationManager.AppSettings.Get("TimeElapsedInMinutes"));
              }
              catch (Exception ex)
              {
                  //Em caso de falha ficam 5 minutos
                  call.InsertLog("PV/S&amp;B Win Service StartPervasive (time)", ex.Message, "");
                  time = 5;
              }
              this.timer = new System.Timers.Timer();
              timer.Enabled = true;
              timer.AutoReset = true; //Necesário para que o srviço se repita
              timer.Interval = 1000 * 60 * time; //Cálculo para minutos
              timer.Elapsed += new ElapsedEventHandler(Elapsed);
          }
          catch (Exception ex)
          {
              call.InsertLog("PV/S&amp;B Win Service StartPervasive", ex.Message, "");
              OnStop();
          }
      }
  
      protected void Elapsed(Object sender, ElapsedEventArgs e)
      {
          try
          {
              timer.Interval = Convert.ToInt32(ConfigurationManager.AppSettings.Get("TimeElapsedInMinutes"));
              StartProcess();
          }
          catch (Exception ex)
          {
              call.InsertLog("PV/S&amp;B Win Service Elapsed", ex.Message, "");
          }
      }
  
      private static void StartProcess()
      {
          try
          {
              string directory = ConfigurationManager.AppSettings.Get("WorkingDirectory");
              string file = ConfigurationManager.AppSettings.Get("FileToRun");
  
  
              //Execução dos processo (ficheiro)
              Process process = new Process();
  
              process.StartInfo.WorkingDirectory = directory;
              process.StartInfo.FileName = directory + @"\" + file;
              process.StartInfo.Arguments = "";
              process.StartInfo.UseShellExecute = false;
              process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
  
              process.StartInfo.CreateNoWindow = false;
  
              process.StartInfo.RedirectStandardOutput = false;
  
              process.Start();
          }
          catch (Exception ex)
          {
              throw ex;
          }
      }
  </code></pre>