What is the strange problem about Windows Service ServicesDependedOn?

Source: Internet
Author: User

What's the strange question about Windows ServicesDependedOn ???

The Code is as follows:

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>

/// Obtain the dependency service of the configuration file

/// </Summary>

/// <Returns> </returns>

Private string [] GetDepengOnServices ()

{

String [] services = null;

String allService = ConfigurationManager. deleettings ["DependOnService"];

Services = new string [] {allService };

// Return services;

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

{

Services = allService. Split (';');

}

Else

{

Services = new string [] {allService };

}

Return services;

 

}

}

GetDepengOnServices () written in the preceding method reports an error during installation.

No error will be reported if you change it to the following method:

/// <Summary>

/// Obtain the dependency service of the configuration file

/// </Summary>

/// <Returns> </returns>

Private string [] GetDepengOnServices ()

{

String [] services = null;

String allService = ConfigurationManager. deleettings ["DependOnService"];

Services = new string [] {allService };

Return services;

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

//{

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

//}

// Else

//{

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

//}

// Return services;

 

}

Read configuration section <! -- List of services the service depends on -->

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

After tracking, both methods can produce correct results. Why does the first method report an error during installation ????

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.