C#Windows服务的主要方法 [英] C# Windows Service Main Method

查看:106
本文介绍了C#Windows服务的主要方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇,究竟是如何的主要()方法适用于Windows服务,因为它涉及到服务控制管理器。当它执行?它是如何挂接到操作系统?难道执行安装服务时?我知道这是执行时的OnStart()被调用由单片机,的onStop()它已经运行,所以我们不会再执行它。

I'm curious how exactly the Main() method works in a windows service as it relates to the Service Control Manager. When is it executed? How does it hook into the OS? Is it executed when a service is installed? I know it is executed when OnStart() is called by the SCM, OnStop() it's already running so we wouldn't execute it again.

如果有人知道了很多关于这方面,可以阐述我会AP preciate吧。

If anyone knows a lot about this area and can elaborate I would appreciate it.

我是一个expeirenced程序员,我并不需要的主要方法做什么一般......它是如何工作的,同时使用Windows服务的说明。

I am an expeirenced programmer, I don't need a description of what the Main Method does in general...just how it works in conjunction with windows services.

推荐答案

当您使用控制面板小程序来告诉服务启动SCM启动过程;这将导致主内的code()来运行。在main()方法的ServiceBase.Run()线挂钩相关的服务到SCM谁再调用的OnStart()方法中的每个ServiceBase.Run()方法调用指定的服务。

When you use the Control Panel applet to tell the service to start the SCM launches the process; this causes the code inside of Main() to run. The ServiceBase.Run() line in the Main() method hooks the associated services into the SCM who then calls the OnStart() method for each of the services specified in the ServiceBase.Run() method call.

这篇关于C#Windows服务的主要方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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