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"/>
跟踪后,两种写法都能得出正确的结果,为什么 第一种写法在安装过程中会报错????