触发Windows服务的最佳方法 [英] best way to trigger windows service

查看:195
本文介绍了触发Windows服务的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows应用程序,该应用程序应该每天发送电子邮件,我已经使用Windows Service完成了此操作.我将使用Windows Task Scheduler触发该服务.我还应该在该服务中设置计时器吗?如果不是,当使用Windows Task Scheduler触发服务时,它将调用onstart()事件吗?如果我在onstart()事件中写我的电子邮件发送代码可以吗?

i have a windows application which should send email on daily basis ,i have done this using windows service.i will trigger the service using windows task scheduler.should i set the timer inside the service as well? if not, when the service is triggered using windows task scheduler will it invoke onstart() event? is it ok if i write my email sending code in onstart() event?

推荐答案

如果您正在使用Windows Scheduler启动该服务,则可能会更好使用简单的控制台应用程序代替Windows服务.
If you are using Windows Scheduler to start the service, it might be better just to use a simple Console Application instead of a windows service.


正如Wayne所说的,您不需要Windows服务.

您想在特定的时间或间隔做某事吗?然后使用调度程序,让它仅在没有UI的情况下执行控制台应用程序或Windows窗体应用程序. :)

刚开始引入Windows服务会使您需要做的事情变得复杂,而这并不是服务设计的目的.出于某种原因(例如托管WCF终结点,监视文件系统),服务应该是必须始终运行"的东西
As Wayne has said, you don''t need a windows service for this.

You want to do something at a particular time or interval? Then use the scheduler and simply have it execute a Console Application or a windows forms application, just with no UI. :)

Introducing a windows service just over complicates what you need to do and isn''t what a service is designed for anyway. A service should be something that is required to be ''always running'' for whatever reason (e.g hosting a WCF endpoint, monitoring a file system)


这篇关于触发Windows服务的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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