Timer interval not change while running the windows service in C#
-
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
-
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
-
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
Write your own config system and read it on each cycle. Personally, I use a database for that.
-
Write your own config system and read it on each cycle. Personally, I use a database for that.
Thanks. I have created an xml file and stored interval . While running the windows service interval is set well through xml. Regards Rajesh
rajesh