简体   繁体   English

Windows 服务与任务计划程序 - 手动启动

[英]Windows Service vs Task Scheduler - manual start

I am trying to develop an application that will scan a website, get data from the website and save that data into database 3x per day at given hour that can be set in xml configuration file.我正在尝试开发一个应用程序,该应用程序将扫描网站、从网站获取数据并将该数据每天 3 次保存到可以在 xml 配置文件中设置的给定时间的数据库中。 As an addition group of users can trigger the start of the application manually max few times per day.作为额外的用户组,每天最多可以手动触发应用程序的启动几次。

I am looking for pros and cons of using a windows service for this solution or should I set a 3 scheduled tasks that will run the console application?我正在寻找为此解决方案使用 Windows 服务的利弊,还是应该设置 3 个将运行控制台应用程序的计划任务?

If I will decide to use a windows service then what is the best way to trigger a manual start of the service while the service is already running?如果我决定使用 Windows 服务,那么在服务已经运行时触发手动启动服务的最佳方法是什么? The group of users will have some kind of web interface to trigger manual start.用户组将有某种 Web 界面来触发手动启动。

This could be easily done using a scheduled task.这可以使用计划任务轻松完成。 I would just set a 3x scheduled tasks that will run the application at given time and the group of users could just start the .exe file from the web interface.我只会设置一个 3x 计划任务,该任务将在给定时间运行应用程序,而用户组只需从 Web 界面启动 .exe 文件。 However how to only allow the user to run a manual trigger only if application is not already running?但是,如何仅在应用程序尚未运行时才允许用户运行手动触发器?

Since the UI is ultimately in web, and thus the service itself won't need any UI, I would go with Windows service which can be triggered to start by the user through web or automatically as the time comes (by its internal code).由于 UI 最终在 Web 中,因此服务本身不需要任何 UI,我将使用 Windows 服务,该服务可以由用户通过 Web 触发或在时间到来时自动启动(通过其内部代码)。

Then, either:然后,要么:

  1. In the service it has something to indicate its status as running which can be captured by the web app to see it, or,在服务中,它有一些东西表明它的状态为运行,可以被网络应用程序捕获以查看它,或者,
  2. In the web, there is mechanism to request/monitor the service status在网络中,有请求/监控服务状态的机制

Is quite flexible I think.我认为是相当灵活的。 I would go with whichever is easier.我会选择哪个更容易。

I picked the task scheduler option for my case.我为我的案例选择了任务调度程序选项。 It was easier to implement the manual triggering by users mechanism.更容易实现用户机制的手动触发。

Pros - Triggers can be added easly using the taks scheduler library.优点 - 可以使用 taks 调度程序库轻松添加触发器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM