简体   繁体   English

控制台应用程序服务-我需要注意些什么吗?

[英]Console Application to Service - do I have to note something?

I'm coding a console application that is reading and writing some stuff at different intervals during the day. 我正在编写一个控制台应用程序,该应用程序在白天以不同的时间间隔读写某些内容。 I want this later (if its "final") as a service. 我希望稍后(如果它是“最终”)作为服务。 For now a simple console application is better (that's how I thought) because its easier to use and I can see the result without having to register/start/end the service. 现在,一个简单的控制台应用程序会更好(这就是我的想法),因为它易于使用,而且无需注册/启动/结束服务就可以看到结果。 Is it easy to later, if I'm done with the testing, just create a new service project and copy the code from the console application? 以后是否很容易,如果我完成了测试,只需创建一个新的服务项目并从控制台应用程序中复制代码?

I heard now that we should not use Timer in a service. 现在我听说我们不应该在服务中使用Timer But I'm using System.Threading.Timer in my console application a lot. 但是我在控制台应用程序中System.Threading.Timer使用System.Threading.Timer Does it mean that I'll be in trouble? 这是否意味着我会遇到麻烦? Is it this "testing on console app and then using it on service" thing not a good idea? 这不是“在控制台应用程序上测试然后在服务上使用它”的主意吗? Any suggestions? 有什么建议么?

You can create Windows service and Right click->Properties and change Output Type as Console Application do your developement.Once you have done with development change back Output Type as Windows Application. 您可以创建Windows服务,然后右键单击->属性,然后将“输出类型”更改为“控制台应用程序”来进行开发。完成开发后,将“输出类型”更改回Windows应用程序。

Take a look at this link to know deep about the both timers. 看一下此链接,以深入了解这两个计时器。

The problem with System.Threading.Timer is that there's no easy way to start/stop the timer. System.Threading.Timer的问题在于没有简单的方法来启动/停止计时器。 And because of that, you can't realiably use it for tasks which could possibly take LONGER than the timer interval. 因此,您无法切实地将其用于可能比计时器间隔更长的任务。

Switch to System.Timers.Timer instead: 改用System.Timers.Timer

http://netpl.blogspot.com/2010/05/systemwindowsformstimer-vs.html http://netpl.blogspot.com/2010/05/systemwindowsformstimer-vs.html

A good solution for you - is to try Application As Service software 对于您来说,一个好的解决方案是尝试“ 应用程序即服务”软件

You can launch every application as a service. 您可以将每个应用程序作为服务启动。

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

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