启动窗口服务的C#语法 [英] c# Syntax for start window services

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

问题描述

我的c#项目在我的本地计算机中(在开发环境中).我想调试我的代码,但它的意思是直接启动输出具有clas库canot的输出类型的项目"为了调试该项目,请添加可执行文件引用该库项目的解决方案".因为我正在调试开发环境中的代码,所以我的计算机中没有adUserSync或indexer.在没有将我的代码投入生产和调试的情况下,在我的机器上的代码中启动服务的语法是什么.

My c# project is in my local machine ( in dvelopment environment ).I want to debug my code but its saying "a project with an output type of clas library canot be started directly" "inorder to debug this project add an executable project to this solution which references the library project". because i''m debuging the code in the develpment envirnment i dont have the adUserSync or indexer in my machine. what is the syntax for starting the services in my code in my machine without puting my code to production and debug.

推荐答案

没有这样的语法. Windows服务以其他方式托管,并由Windows服务控制器运行.为此,您需要以正确的方式安装Service应用程序.然后,您需要使用系统服务"小程序(services.msc)来启动服务.

为了安装服务,您需要对服务应用程序进行可安装"编程.实际上,您可以根据应用程序的运行方式来开发应用程序,使其可以用作交互式应用程序和Windows服务.如果这样做,则可以包括安装代码,还可以包括与服务控制器一起使用的代码,以启动/停止/重新启动服务.这两个琐事可以在应用程序的交互部分(当然,也可以是单独的应用程序)中实现.

请更详细地查看我过去的解决方案:
如何以编程方式安装Windows服务 [ ^ ] .

-SA
There is no such syntax. The Windows Service is hosted in a different way and is run by Windows Service Controller. To get to this point, you need to install you Service application in a proper way. Then you need to use system "Services" applet (services.msc) to start the service.

In order to install service, you need to program your service application "installable". In fact, you can develop your application the way it can be used as an interactive application and a Windows Service, depending on how it is run. If you do that, you can include installation code and optionally the code working with the Service Controller to start/stop/restart your service. These two chores can be implemented in the interactive part of your application (or a separate application, of course).

Please see my past solution on more detail:
How to install windows service programmatically[^].

—SA


因此,您正在编写 Windows服务 [ ^ ],而您正在尝试调试呢?

如消息所暗示,您的项目需要配置为控制台应用程序.在项目的属性"对话框中对此进行了更改.

您无法轻松地从IDE调试服务,但这是一个很好的参考: sc [ ^ ]或以编程方式 Windows服务应用程序简介 [ ^ ]
So you''re writing a Windows Service[^], and you''re trying to debug it?

As the message implies, your project needs to be configured as a Console Application. This is changed in the project''s Properties dialog.

You can''t easily debug a service from the IDE, but this is a good reference: How to: Debug Windows Service Applications[^]

If possible, just run it as a normal console application until you''re ready to make it a service. When it''s ready you can install it as a service from the command line using sc[^] or programatically using an Installer with custom actions[^].

This is a good overview of the whole process: Introduction to Windows Service Applications[^]


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

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