Timer not stopping

  • Thread starter Thread starter Priya Bange
  • Start date Start date
P

Priya Bange

Guest
Hi Experts,

The below code works fine which I got from a previously asked thread but now the issue is .

1. If I remove the Console.Readkey() it executes only for 5 times ..
2. If I don't remove the Console.ReadKey() it executes forever and unable to stop using Ctrl + C.


Could you please help with its optimization, that it stops on Ctrl + C and also doesn't run forever.

I require the timer in windows service.


static void Main(string[] args)
{
int interval = int.Parse(ConfigurationManager.AppSettings["interval"]);
System.Threading.Timer timer = new System.Threading.Timer(Start,null,1,interval);

Console.ReadKey();
}

private static void Start(object state)
{
Console.WriteLine("Do something here.");
}


Thanks

Priya

Continue reading...
 

Similar threads

P
Replies
0
Views
177
Policy standard local admin account with Active Di
P
Back
Top