Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Timer interval not change while running the windows service in C#

Timer interval not change while running the windows service in C#

Scheduled Pinned Locked Moved C#
csharptutorialquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rajesh_K_Sharma
    wrote on last edited by
    #1

    Hi I made a window service application and I used system.timers.timer class . I set timer interval from config file. I would like to fire timer as specified interval in config file. It works fine but while running the windows service I want to change timer interval in config file and timer should be fired at latest interval . When I stop the service and restart the service then timer fire as specified value in config file. Pseudo code private System.Timers.Timer timer2 = new System.Timers.Timer(); protected override void OnStart(string[] args) { // dblValue = 30000 double dblValue = Convert.ToDouble(ConfigurationManager.AppSettings.Get("Interval")); timer2.interval = dblValue timer2.Elapsed += new System.Timers.ElapsedEventHandler(timer2_Elapsed); timer2.Enabled = true; } void timer2_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { timer2.Enabled = false; // doing some operation // Now I want to change the value in config file like dblValue = 60000 double dblValue = Convert.ToDouble(ConfigurationManager.AppSettings.Get("Interval")); timer2.interval = dblValue timer2.Enabled = true; } but timer always fired after 30000 milliseconds. But I want , timer should be fired after 60000 milliseconds , means latest value define in config file. Please tell me how to do this ? Regards Rajesh

    rajesh

    A P 2 Replies Last reply
    0
    • R Rajesh_K_Sharma

      Hi I made a window service application and I used system.timers.timer class . I set timer interval from config file. I would like to fire timer as specified interval in config file. It works fine but while running the windows service I want to change timer interval in config file and timer should be fired at latest interval . When I stop the service and restart the service then timer fire as specified value in config file. Pseudo code private System.Timers.Timer timer2 = new System.Timers.Timer(); protected override void OnStart(string[] args) { // dblValue = 30000 double dblValue = Convert.ToDouble(ConfigurationManager.AppSettings.Get("Interval")); timer2.interval = dblValue timer2.Elapsed += new System.Timers.ElapsedEventHandler(timer2_Elapsed); timer2.Enabled = true; } void timer2_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { timer2.Enabled = false; // doing some operation // Now I want to change the value in config file like dblValue = 60000 double dblValue = Convert.ToDouble(ConfigurationManager.AppSettings.Get("Interval")); timer2.interval = dblValue timer2.Enabled = true; } but timer always fired after 30000 milliseconds. But I want , timer should be fired after 60000 milliseconds , means latest value define in config file. Please tell me how to do this ? Regards Rajesh

      rajesh

      A Offline
      A Offline
      Ashfield
      wrote on last edited by
      #2

      Its because config files are only read once and then cached.

      Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

      1 Reply Last reply
      0
      • R Rajesh_K_Sharma

        Hi I made a window service application and I used system.timers.timer class . I set timer interval from config file. I would like to fire timer as specified interval in config file. It works fine but while running the windows service I want to change timer interval in config file and timer should be fired at latest interval . When I stop the service and restart the service then timer fire as specified value in config file. Pseudo code private System.Timers.Timer timer2 = new System.Timers.Timer(); protected override void OnStart(string[] args) { // dblValue = 30000 double dblValue = Convert.ToDouble(ConfigurationManager.AppSettings.Get("Interval")); timer2.interval = dblValue timer2.Elapsed += new System.Timers.ElapsedEventHandler(timer2_Elapsed); timer2.Enabled = true; } void timer2_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { timer2.Enabled = false; // doing some operation // Now I want to change the value in config file like dblValue = 60000 double dblValue = Convert.ToDouble(ConfigurationManager.AppSettings.Get("Interval")); timer2.interval = dblValue timer2.Enabled = true; } but timer always fired after 30000 milliseconds. But I want , timer should be fired after 60000 milliseconds , means latest value define in config file. Please tell me how to do this ? Regards Rajesh

        rajesh

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        Write your own config system and read it on each cycle. Personally, I use a database for that.

        R 1 Reply Last reply
        0
        • P PIEBALDconsult

          Write your own config system and read it on each cycle. Personally, I use a database for that.

          R Offline
          R Offline
          Rajesh_K_Sharma
          wrote on last edited by
          #4

          Thanks. I have created an xml file and stored interval . While running the windows service interval is set well through xml. Regards Rajesh

          rajesh

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups