想在30分钟后拨打Windows服务 [英] Want to call Windows Service after 30 Min

查看:84
本文介绍了想在30分钟后拨打Windows服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我想从文件和更新数据库中读取数据新的时间是在数据库中定义的。

我是为此写Windows服务但你可以告诉我Windows服务如何继续运行和检查时间..

你能告诉我如何每隔30分钟运行一次Windows服务来检查是否有时间



谢谢,

Amit Patel

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

推荐答案

错误的想法。而不是调用服务(没有这样的东西,你甚至不能直接运行它,但你可以用服务控制器停止/启动它,这将是另一个相当不错的主意:-)),你需要有一些永久性的工作服务,有一些线程可以睡30分钟然后做一些动作,然后再循环,或者使用一些计时器。



请注意,线程大部分时间都处于等待状态,不会在这些操作之间浪费任何CPU时间。



还有另一个机会。你可以反复启动一些小任务。但在这种情况下,您不需要开发自己的服务。您需要的服务已存在,称为 Windows任务计划程序,请参阅:

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 [ ^ ]。



见上面的最后一个链接,用于使用Windows任务计划程序。您可以使用任务计划程序托管包装程序在程序中使用其API,请参阅 http://taskscheduler.codeplex.com/ [ ^ ]。



但是,如果可以更简单。
您可以使用Windows实用程序AT.EXE或SchTasks.EXE使用Windows任务计划程序,请参阅:

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
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


这篇关于想在30分钟后拨打Windows服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆