Reputation: 5841
I'm looking at the documentation regarding ServiceController and I can't find anything regarding it's blocking properties.
We start 3 services (using ServiceController
Start method), I was wondering if the start command fires off, and it moves to the next, or if the first has to finish starting, then the second then the third (in this case we'll say that the services are independent of the other services and do not need to be "started" in any particular order)
I wasn't sure of a "good" way to find this information, I can spend the time writing two apps, one that starts the second, and the second won't start "officially" until I hit a button, then I can test whether it's blocking or non, is there documentation that states this, or an easier way?
Note: I'm currently using Visual Studio 2005, if that has any difference in your answer(s).
Upvotes: 0
Views: 866
Reputation: 11216
Using JustDecompile, here is part of the code it gives for the Start method:
try
{
gCHandle = GCHandle.Alloc(hGlobalUni, GCHandleType.Pinned);
if (!UnsafeNativeMethods.StartService(serviceHandle, (int)args.Length, gCHandle.AddrOfPinnedObject()))
{
Exception exception = ServiceController.CreateSafeWin32Exception();
object[] serviceName = new object[] { this.ServiceName, this.MachineName };
throw new InvalidOperationException(Res.GetString("CannotStart", serviceName), exception);
}
}
The native method is declared as
[DllImport("advapi32.dll", CharSet=CharSet.Unicode, ExactSpelling=false, SetLastError=true)]
public static extern bool StartService(IntPtr serviceHandle, int argNum, IntPtr argPtrs);
From the docs for StartService:
When a service is started, the Service Control Manager (SCM) spawns the service process, if necessary. If the specified service shares a process with other services, the required process may already exist. The StartService function does not wait for the first status update from the new service, because it can take a while. Instead, it returns when the SCM receives notification from the service control dispatcher that the ServiceMain thread for this service was created successfully.
Upvotes: 1