简体   繁体   English

控制台应用程序与Windows服务

[英]Console Application versus Windows Service

I have a small C# program that I created that contacts a web service and retrieves and processes datasets. 我创建了一个小型C#程序,它与Web服务联系并检索和处理数据集。 No problem with that after some head scratching and much exploring of stackOverflow - thanks to all who contribute. 经过一些头脑刮擦和探索stackOverflow之后没有问题 - 感谢所有贡献者。

I normally work in the Linux world, so this is a rare foray into the Windows Environment. 我通常在Linux世界工作,所以这是对Windows环境的罕见尝试。 What I need to do is set it up so that TaskScheduler will run this application. 我需要做的就是设置它以便TaskScheduler运行这个应用程序。 There is no console display or interaction, everything is written to log files. 没有控制台显示或交互,所有内容都写入日志文件。

In Linux I would simply use a CRONTASK, but things are a bit different in Windows. 在Linux中我只使用CRONTASK,但在Windows中有些不同。 Is this the ?proper? 这是吗?对吗? way to do this since it will be run once daily? 这样做的方法,因为它将每天运行一次? I considered a windows service but there is a level of complexity that I am not sure is justified. 我考虑过一个Windows服务但是有一定程度的复杂性,我不确定是否合理。

Thoughts? 思考?

If your app is doing small task every so often then a scheduled task is better as you'd be taking up system resources with a service sitting there doing nothing for most of the time. 如果您的应用程序每隔一段时间执行一次小任务,那么计划任务会更好,因为您将占用系统资源,而服务大部分时间都无法执行任何操作。

If you're running your app on a recent version of windows then take a look in the control panel and search for "scheduled tasks". 如果您在最新版本的Windows上运行应用程序,请查看控制面板并搜索“计划任务”。 You will be able to set up a job to run your app daily in there. 您将能够设置一份工作,每天在那里运行您的应用程序。

you will probably script this, so use schtasks.exe to create your scheduled tasks: msdn link to schtasks.exe 您可能会编写此脚本,因此请使用schtasks.exe创建计划任务: msdn链接到schtasks.exe

also, on win7 and later, you can actually migrate the created scheduled tasks in form of xml and import them onto another machine, it's a little easier to manipulate and/or save them if you want. 此外,在win7及更高版本中,您实际上可以以xml的形式迁移创建的计划任务并将其导入另一台计算机,如果您愿意,可以更轻松地操作和/或保存它们。

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

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