?
Solved

How to ensure that service is start after another service

Posted on 2005-03-02
4
Medium Priority
?
372 Views
Last Modified: 2008-01-09
Hello,

I have written a Windows Service that relies on SQL Service and 2 other custom services, but on start up, sometimes, my service is started before those ones, and I'm getting errors. Is there a way to enforce a service start only after some other service is started, and similarly, once some other service has been stopped, cascade it on all dependant services.

Thank you
0
Comment
Question by:RodionP
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
heintalus earned 1000 total points
ID: 13444109
When you add your installer to your service it has a ServicesDependedOn Property where you can specify other services that yours depends on.

Quote from online Help :-
The information from this property is written to a key in the registry. When the user (or the system, in the case of automatic startup) tries to run the service, the Service Control Manager (SCM) verifies that each of the services in the array has already been started.

If any service in the array is not running then, the SCM tries to start them. This includes services with Manual StartType.

If any service upon which this service depends fails to start, this service will not start.

HTH
Andy
0
 
LVL 1

Author Comment

by:RodionP
ID: 13445297
Any code examples would be appreciated
0
 
LVL 11

Expert Comment

by:sachiek
ID: 13445815
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemServiceProcessServiceControllerClassStatusTopic.asp

Check out here.

You have to use this property to ensure that particular service had started. Then you can initate to start secound service.


Hope you got it.

Sachi
0
 
LVL 10

Expert Comment

by:heintalus
ID: 13445982
You dont need code to do it, have you added an installer to your service ?

If so open it up & select the serviceInstaller, have a look at it's properties & you will see one called ServicesDepended on which is a string array for all services that it depends upon, simple add the names of any services you want to this array via the properties window, for example if your service depends on Microsoft Message Queueing you'd add in MSMQ i.e. the service name you see if you look at the services properties from within Services.

HTH
Andy
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Integration Management Part 2
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question