Click here to Skip to main content
15,905,874 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,
I am designing a windows service in c# . I want to run my function i.e "MethodToExecute()" daily at 11 am . I am unable to find the exact solution to trigger my function daily at particular time. Please provide me an solution to for triggering daily thAT function at particular time in Windows Service c#
When I created a siolution two events are generated

protected override void OnStart(string[] args)
{

}

  protected override void OnStop()
{
}



Please provide me the perfect code to trigger that finction daily at 11 am

Thanks in advance.
Posted

1 solution

If you've got a process to run at a specific time, that would normally be done by a scheduled task, not a service.

But, you'd have to spinup a timer that triggers, say, once a minute. In the callback for the timer, check the current time against your scheduled time. If the current time is greater than the system time, reschedule the event for the next day and run your worker code.
 
Share this answer
 
Comments
jing567 7-Jan-15 23:51pm    
hi Dave,
I am not aware to scheduile a taks , Is it possible to schedule a task for windows service?
Dave Kreskowiak 8-Jan-15 0:14am    
No and it's pointless to do so.

A scheduled task is usually just a console application that is run by the Windows Tasks Scheduler. All you do is create your application as a Console app and setup it to run in the Task Scheduler which you'll find in Control Panels -> Administrative Tools.
jing567 8-Jan-15 0:15am    
Yia thats a very good reply... i am converting my application from Windows service to console app.... This would solve my problem .... thanku very much :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900