I tried to identify the issue in below given code. timer is calling the method only for first instance but not calling it after 2500 ms time interval. Is there something that i am missing.Below is my code
public class Program
{
public void CheckStatus(object stateInfo)
{
Console.WriteLine("I am Executed");
}
public static void Main(string[] args)
{
try
{
Program p = new Program();
Console.WriteLine("Creating timer.\n");
var stateTimer = new Timer(state => p.CheckStatus(state), null, 0, 2500);
}
catch (Exception ex)
{
Console.WriteLine("Exception");
}
}
}
In above code i am tring to execute the method "CheckStatus" after every 2500 ms and for first execution it should execute immediately (pass parameter as 0) I also tried to replace time value with timespan but it also did not worked for me