zoukankan      html  css  js  c++  java
  • Windows服务ServicesDependedOn的奇怪问题?

    Windows服务ServicesDependedOn的奇怪问题???

    代码如下

    public partial class WinServicePWServiceInstaller : Installer

        {

     

            private ServiceProcessInstaller process;

            private ServiceInstaller service;

            private const string m_SERVICENAME = "myService";

     

            public WinServicePWServiceInstaller()

            {

     

                InitializeComponent();

     

                process = new ServiceProcessInstaller();

                process.Account = ServiceAccount.LocalSystem;

     

              

                service = new ServiceInstaller();

                service.ServiceName =m_SERVICENAME;

                service.StartType = ServiceStartMode.Automatic;

                service.ServicesDependedOn = GetDepengOnServices();

     

                Installers.Add(process);

                Installers.Add(service);

     

            }

            /// <summary>

            ///获取配置文件的依赖服务

            /// </summary>

            /// <returns></returns>

            private string[] GetDepengOnServices()

            {

                string[] services=null;                              

                string allService = ConfigurationManager.AppSettings["DependOnService"];

                services = new string[] { allService };

                //return services;

                if (allService.IndexOf(';') != -1)

                {

                   services = allService.Split(';');

                }

                else

               {

                   services =new string[]{ allService};

               }

               return services;

     

            }

        }               

    按以上方法写的 GetDepengOnServices(),在安装过程中报错。

    改成一下方法不会报错

    /// <summary>

            ///获取配置文件的依赖服务

            /// </summary>

            /// <returns></returns>

          private string[] GetDepengOnServices()

            {

                string[] services=null;                              

                string allService = ConfigurationManager.AppSettings["DependOnService"];

                services = new string[] { allService };

                return services;

                //if (allService.IndexOf(';') != -1)

                //{

                //    services = allService.Split(';');

                //}

                //else

                //{

                //    services =new string[]{ allService};

                //}

                //return services;

     

            }                  

    所读的配置节 <!--本服务依赖的服务列表-->

        <add key ="DependOnService" value ="MSSQLSERVER"/>

    跟踪后,两种写法都能得出正确的结果,为什么 第一种写法在安装过程中会报错????

  • 相关阅读:
    笔试-2020软件工程师Java(上海)中科创达(收获很多,自己基础还是不行)
    SpringCloud-Spring Cloud 2 Finchley.M9报错问题
    IDEA 实体类生成serialVersionUID
    idea创建maven项目时出现Unable to import maven project: See logs for details
    Eclipse可以执行jsp文件却无法访问Tomcat主页
    已知n个正数:wi, 1<=i<=n, 和M。要求找出{wi }的所有子集使得子集内元素之和等于M。例如: n=4, (w1,w2,w3,w4)=(11,13,24,7),M=31 则满足要求的子集是(11,13,7)和(24,7)。
    嵌入式系统外部中断实验(按下按键,LED灯依次熄灭)
    嵌入式系统按键实现(按下按钮,LED灯熄灭)
    如何跳转一个由两个框架组成的页面
    对某个页面的过滤
  • 原文地址:https://www.cnblogs.com/hbb0b0/p/1581766.html
Copyright © 2011-2022 走看看