This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
开发者_Python百科Closed 4 years ago.
Improve this questionI have created a windows service.
I want to invoke it repeatedly for every 5 seconds through out the day.
I had scheduled a windows task to do that but the windows service doesnt seem to get invoked when invoked from the windows task.
I am using `NET START "Windows Service Name.exe" to schedule task under windows task scheduler.
It runs properly when I manually try to start the service.
What could be wrong?
Your approach is incorrect. Instead of starting the service every 5 seconds, your service should start only once and do something every 5 seconds.
The service main function should have a loop which starts when your service is initialized and ends only when the service is stopped (for example when the computer is shutdown). This loop can check for a stop message or event.
Inside the loop you can also perform the operation you want every 5 seconds. You can use a timer or a simple Sleep(5000). You can also do this on a separate thread so it doesn't hold off the timer.
If your starting the service every 5 seconds, why use a service at all?
Got the solution..!!
Added a new windows task to close the service using NET STOP command.
This helped me.
Hope this helps others. :)
what OS are you using?
I'm not getting it completely though. A service is something you start automatically or manually and once it runs, it runs, until you stop the service. A Task is something that you can control when and how it will fire and under which credentials it will run and what file it should execute.
I'm reading Your question thus as : you've got a bat file that has the 'net start...' cmd in it and that bat file you want to run every 5 seconds?
精彩评论