I am using System.Timers.Timer
Class and I want to change it's Interval
in the elapsed function. When i set Elapsed
property to different value, somehow elapsed function starts firing and firing again althrough timer's Autoreset
property is set to false.
my code:
var timer = new Timer()
{
Interval = 1000,
AutoReset = false,
};
timer.Enabled = true;
timer.Elapsed += (sender, eventArgs) =>
{
Console.WriteLine("Timer fires");
timer.Interval = 2000;
};
The code results in firing timer again and again when i just wanted to change interval for the latter use of the timer.
It would be nice to know why this happens and what should i do to achieve desired behaviour.