Windows Service:如何做(“可以用它们做什么?"); [英] Windows Service: How to do("What can be done with them?");

查看:457
本文介绍了Windows Service:如何做(“可以用它们做什么?");的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近学习了如何创建Windows服务.
(简单Windows服务示例 [ 出于这个原因,我还想知道使用服务可以做什么.

I recently learnt how to create windows service.
(Simple Windows Service Sample[^])

But, however, I have a question: What do you use them for? ... and HOW?

Of course we see a lot of services on windows for different purposes.
I just wanted to know how to do something other than a typical "Hello World"-like service.
For this reason I also wanted to know what ever can be done with services.

推荐答案

好.让我们举个例子,一个真实的场景:
您需要每个星期一向注册到给定网站的所有用户发送电子邮件.您可以使用此Windows服务,该服务将继续运行-每个星期一它将自动发送具有指定内容的电子邮件.您不需要在它们之间进行任何手动干预.
Ok. Lets pick an example, a real life scenario:
You need to send an email every monday to all the users registered to a given webstite. You can have this windows service in place that will keep running - every monday it will automatically send the email with content specified. You don''t need to have any manul intervention in between.


服务与普通程序不同,不需要在交互式会话的上下文中运行.因此,无论何时需要完成某件事,而无需任何人登录,服务都是解决问题的好方法.

当然,服务会带来完全不同的问题:您不能(轻松地)向用户指出错误,因为不一定有用户登录(服务器通常是这种情况). >
如果您必须编写服务,则使其也可以作为应用程序运行(我相信CP上有一篇文章).它使开发和调试变得更加容易.
Services, unlike normal programs, need not run in the context of an interactive session. So whenever you need something to be done, without the need of having anyone log in, a service is a good way to deal with the problem.

Of course, services come with a whole different bag of problems: you can''t (easily) indicate errors to users, because there''s not necessarily a user logged in (which is often the case with servers).

If you ever have to write a service, make it also run as an application (I believe there is an article on it here at CP). It makes development and debugging a lot easier.


这篇关于Windows Service:如何做(“可以用它们做什么?");的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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