0

I am looking to do an action on every day at a particular time like triggers in sql, but here i am looking to do this in c#.net, can any one please help me,

Thanks

Srikanth
  • 147
  • 1
  • 2
  • 15

1 Answers1

2

In general you are creating loop and then check if it's time for your action. It should be alwasy running process (service, or application in tray, etc).

It depends on how clear you need to be in your timer: if it needs to be second in second you need to create interval in 1 second and in Elapsed handler check you target time with current one, if true - fire alarm (event).

Samich
  • 29,157
  • 6
  • 68
  • 77
  • Actually i need to perform an action at 00:00 hours of every day that means once a day, – Srikanth Aug 23 '12 at 10:38
  • So if it should be exactly in 00:00 you need to set interval in 1 minute, if it's OK to run it in any minute till the 01:00 - you can set to 1 hour.. So, I prefer 1 minute, it's not heavy operation to compare 2 dates. – Samich Aug 23 '12 at 10:40
  • 1
    btw, similar question http://stackoverflow.com/questions/3243348/how-to-call-a-method-daily-at-specific-time-in-c – Samich Aug 23 '12 at 10:41
  • 1
    and complete tutorial about it: http://www.aspfree.com/c/a/C-Sharp/Timer-Objects-in-Windows-Services-with-C-sharp-dot-NET/ – Samich Aug 23 '12 at 10:42
  • I think i understand some thing that I need to create windows service and schedule that service... am I going in right direction? – Srikanth Aug 23 '12 at 10:43
  • You actually not scheduling the service, you making timer inside the service which will perform your scheduling. In other words you are making your own scheduler. – Samich Aug 23 '12 at 10:45
  • Yeah I got it the link you posted is really got a good explanation and top be frank a good solution for my scenario, thank you very much – Srikanth Aug 23 '12 at 11:25
  • I think it would be much easier to just create the app that performs your action and then use the Windows Task Scheduler to have it executed each day at midnight! – Chris Dunaway Aug 23 '12 at 16:36