Windows服务问题. [英] Problem with windows service.

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

问题描述

我创建了一个简单的Windows服务,该服务会在两秒钟的间隔后发出蜂鸣声.当我尝试使用作为exe文件的应用程序安装程序来安装服务时,出现错误无法通过命令行或调试器启动服务.必须首先安装Windows服务(使用installutil.exe),然后再启动使用ServerExplorer,Windows服务管理工具或NET START命令."但在2秒钟后发出哔声,并在显示错误消息时发出哔声.
我尝试使用installutil形式的.NET命令安装服务,提示服务已成功安装,但没有发出哔声.这是我使用的代码.我没有服务编程方面的经验,因此低估了服务的生命周期可能会出错.我有ASP.NET开发经验,因此几乎没有提示可以帮助我进行分类.

I created simple windows service that beeps after a interval of two seconds. When I try to Install the service using the application installer that is the exe file, it gives an error that "Cannot start service form the command line or a debugger. A windows service must first be installed (using installutil.exe) and then started with the ServerExplorer, Windows Services Administrative tool or the NET START command." but beep after 2 seconds the beep is generated while the error message is displayed.
I tried installing the service using the installutil form .NET command prompt the service is successfully installed but the sound of beep is absent. Here is the code I used. I do not have any experience in service programming so there may be an error in understating the life cycle of service. I have experience in ASP.NET development so little hint can help me sort out things.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.IO;
namespace WindowsService1
{
    public partial class Service1 : ServiceBase
    {
        public Service1()
        {
            InitializeComponent();
            timer1.Start();
        }
        protected override void OnStart(string[] args)
        {
            timer1.Start();
        }
        protected override void OnStop()
        {
        }
        //private void InitializeComponent()
        //{
        //    timer1.Start();
        //}
        private void timer1_Tick(object sender, EventArgs e)
        {
             Console.Beep();
        }
        static void main()
        {
            System.ServiceProcess.ServiceBase[] ServicesToRun;
            // More than one user Service may run within the same process. To add
            // another service to this process, change the following line to
            // create a second service object. For example,
            //
            //   ServicesToRun = new System.ServiceProcess.ServiceBase[] {new Service1(), new MySecondUserService()};
            //
            ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service1() };
            System.ServiceProcess.ServiceBase.Run(ServicesToRun);
        }
    }
}

推荐答案

看看链接 ^ ]进行了详细说明和示例.
Have a look at the link How to create a setup project for a Windows Service application in Visual C# [^] it is explained with detail and sample.


您需要在服务解决方案中拥有一个安装程序项目,并且需要修改该项目.根据youtr服务的安装方式. Google是您的朋友.

我在Google上搜索了"C#Windows服务安装程序项目codeproject",并获得了740,000个结果.
You need to have an installer project in your service solution, and you need to modify that project according to the way youtr service is installed. Google is your friend.

I searched for "C# windows service installer project codeproject" on google and got 740,000 results.


installutil YourapplicationName \ bin \ debug \ YourApplicaionName.exe ....
installutil YourapplicationName\bin\debug\YourApplicaionName.exe....


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

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