Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi All,

I want to read data from file and update DB new time is defined in the databasee.
I am writing windows service for that but can you please let me know how can windows service keep running and checking time..
Can you please let me know how to run Windows service after every 30 min to check whether time

Thanks,
Amit Patel
Posted
Comments
ZurdoDev 27-May-15 13:21pm    
You use a timer. Tons of examples online if you look at windows service and timer.
Sergey Alexandrovich Kryukov 27-May-15 14:36pm    
Or Thread.Sleep. Or Windows Task Scheduler.
Please see Solution 1.
—SA
Sergey Alexandrovich Kryukov 27-May-15 15:55pm    
The question title is misleading. To make is consistent with the question, add "every" in "after every 30 min". I answered your question.
—SA

1 solution

Wrong idea. Instead of "calling the service" (there is no such thing, and you cannot even directly run it, but you could stop/start it with a service controller, which would be another quite a bad idea :-)), you need to have permanently working service, with some thread which sleeps for some 30 min and then do some action, and then repeat it in circle, or, alternatively, use some timer.

Note that the thread will be in a wait state most of the time, not wasting any CPU time between those actions.

There is another opportunity. You can repeatedly start some small task. But in this case, you would not need to develop your own service. The service you need already exists, called Windows Task Scheduler, see:
http://en.wikipedia.org/wiki/Task_Scheduler[^],
http://msdn.microsoft.com/en-us/library/aa383614.aspx[^],
http://msdn.microsoft.com/en-us/library/aa384006%28v=VS.85%29.aspx[^].

See the last link above for use of the Windows Task Scheduler. You can use its API in your program using Task Scheduler Managed Wrapper, see http://taskscheduler.codeplex.com/[^].

But if can be even simpler.
You can use Windows Task Scheduler using Windows utilities AT.EXE or SchTasks.EXE, see:
http://en.wikipedia.org/wiki/At_(Windows)[^],
http://technet.microsoft.com/en-us/library/bb490866.aspx[^],
http://en.wikipedia.org/wiki/Schtasks[^],
http://msdn.microsoft.com/en-us/library/windows/desktop/bb736357%28v=vs.85%29.aspx[^].

—SA
 
Share this answer
 

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