如何按时运行Window Service [英] How to run Window Service on time basis

查看:75
本文介绍了如何按时运行Window Service的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我已经创建并部署了Windows服务,我想以每1分钟或5分钟的时间限制启动此服务,如下所示,





任何人都可以帮助我。




- Srinivas .P

Hi,

I Have created and deployed windows service, i want to fire this service in a time bound means for every 1 min or 5 mins like this,


Can any one can help me.


- Srinivas .P

推荐答案

您可以使用Windows任务计划程序(您必须在那里使用NET命令,例如,参见< a href =http://www.coretechnologies.com/WindowsServices/FAQ.html#StartStopFromCommandLine>如何从命令行启动/停止Windows服务? [ ^ ]。

在我看来,你的是一个非常奇怪的场景:通常服务是连续运行的。
You may use the Windows Task Scheduler for that (you have to use the NET command there, see, for instance "How do I start/stop a Windows Service from the command line?"[^].
In my opinion, your is a pretty strange scenario: usually services are meant to run continuously.


这不是最好的想法,按时间为服务加注星标.Windows服务真的被设计为永久执行,这是e的主要目的。因此,最好让某些服务在阻塞状态下运行(不要浪费任何CPU时间),并通过计时器或在执行中需要延迟的单独线程中执行所需的方法。当调用 System.Threading.Thread.Sleep 时,线程也被阻塞(保持等待状态)并且不占用任何CPU时间。



-SA
This is not the best idea, to star a service on time basis. The Window Services are really designed to be executed permanently, this is one of the main purposes of them. So, it's much better to keep some service running in a blocked state (not wasting any CPU time) and execute required method(s) either by timer, or in a separate thread with required delays in execution. When System.Threading.Thread.Sleep is called, the thread is also blocked (kept in a wait state) and does not spend any CPU time.

—SA


这篇关于如何按时运行Window Service的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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