• 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"/>

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

  • 相关阅读:
    【Android】Android消息处理机制
    【Android】Sensor框架HAL层解读
    【Android】Sensor框架Framework层解读
    【流媒体】初识流媒体与流媒体技术
    【Git】Git与GitHub 入门
    【Delphi】基于状态机的串口通信
    【Delphi】SPComm注意事项
    【Android】事件输入系统-代码层次解读
    【Android】事件处理系统
    【Android】窗口机制分析与UI管理系统
  • 原文地址:https://www.cnblogs.com/hbb0b0/p/1581766.html
Copyright © 2020-2023  润新知