我在哪里可以找到Windows服务的生命周期的详细视图,开发.NET? [英] Where can I find a detailed view of the lifecycle of a Windows Service as developed in .NET?

查看:158
本文介绍了我在哪里可以找到Windows服务的生命周期的详细视图,开发.NET?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在哪里可以找到Windows服务的生命周期的详细视图,开发.NET?我把我这样问,因为我不知道,一个足够详细的描述可以在这里贴了,但如果你认为你可以请随意尝试。

Where can I find a detailed view of the lifecycle of a Windows Service as developed in .NET? I put my question this way because I am not sure that a detailed enough description can be posted here, but if you think you can please feel free to try.

不正确的答案的一个例子是从MSDN页描述的糊剂:介绍到Windows服务应用程序。这是几乎没有足够详细。举例来说,是一个服务卸出内存,并为此将调用Dispose方法?或者它只是获得由的onStop方法调用OnStart方法停止,只有重新启动时没有初始化?

An example of an incorrect answer would be a paste of the description from the MSDN page: Introduction to Windows Service Applications. It is not nearly detailed enough. For instance, is a service unloaded out of memory, and therefor the Dispose method is called? Or does it just get stopped by the OnStop method, only to be re-started without initialization by calling the OnStart method?

由于这样的事实,我的问题已经解决,和presents同时另外一个问题,这里有一些对对象的生命周期(我现在知道也适用于服务),供未来的参观者这个问题:

Due to the fact that my question has been answered, and presents another question at the same time, here are some references to object lifecycles' (which I now know also applies to services) for use by future visitors to this question:

计算器 - 什么是.NET对象生命周期

tutorials.beginners.co.uk/read/id/188

tutorials.beginners.co.uk/read/id/188

developerfusion.com/article/1047/new-objectoriented-capabilities-in-vbnet/3 /

developerfusion.com/article/1047/new-objectoriented-capabilities-in-vbnet/3/

享受!

推荐答案

Windows服务是有效地暴露在服务管理器一些额外的方法的应用程序进行控制,即停止()开始()暂停()继续()(或等值)。

The windows service is effectively an application with a few extra methods exposed for the service manager to control it, namely Stop(), Start(), Pause(), Continue() (or equivalents).

在开始被调用时创建应用程序域,初始化服务类和叫开始()方法。在停止停止()方法被调用的应用程序域从内存中卸载之前。

When Start is called the application domain is created, the service class initialised and the Start() method called. On stop the Stop() method is called before the application domain is unloaded from memory.

您可以看到这与任务管理器。该应用程序不存在于内存中,直到开始被调用,它消失停止完成后。

You can see this with task manager. The application doesn't exist in memory until the start is called and it disappears after the Stop is completed.

因此​​,我认为,回答你的生命周期的问题在于一个标准的.NET应用程序的生命周期中,无论是命令行,的WinForms或asp.net。

Therefore I believe that the answer to your lifecycle question lies in the lifecycle of a standard .NET application, be it command line, winforms or asp.net.

我也建议的是,如果你是依赖于Dispose方法则是有可能的一个缺陷在设计lieing的地方,在多数情况下的资源清理被处置应更频繁地处理比当服务主机调用组件部署。大多数服务都mearly一种机制,用于响应系统事件的地方,在这种情况下来自非托管资源的情况下,你可能只需要获取资源的OnStart并释放它的onStop,在该事件不会对原产于非托管的情况下,空间,那么你可能想抓住并释放非托管资源更JustInTime型的方式在这里被你抓住他们,因为只有当你需要他们,并(通过其Dispose方法)释放它们的资源,只要你能。进一步阅读请查看何时以及如何使用配置和的。净Dispose模式

I would also advise though that if you are dependent on the Dispose method then there is a probably a flaw lieing somewhere in your design, under most circumstances the resources cleaned up by a Dispose should be disposed more frequently than when the Service Host calls your component to Dispose. Most services are mearly a mechanism for responding to a system event somewhere, in the cases where this event comes from an unmanaged resource, you probably only want to grab the resource OnStart and release it OnStop, in situations where the event is not originating in unmanaged space then you probably want to grab and release the unmanaged resources in a more JustInTime type manner where by you grab them as a resource only when you need them and release them (via their Dispose method) as soon as you can. For further reading check out When and how to use dispose and .Net dispose pattern

这篇关于我在哪里可以找到Windows服务的生命周期的详细视图,开发.NET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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