1

I have a .NET windows service which acts as a host for some wcf. In the OnStart method the service hosts are created and started. The service is configured to startup automatically. This works well on Windows 7 (32bit and 64bit) and it can be startet with "net start" on Windows XP Pro SP3. The service startup with "net start" command takes about 20 seconds.

But when Windows XP Pro SP3 is booting there's a timeout message in the event log. The service itself does not fail to startup, though do its dependencies. The problem can be reproduced on various XP machines. Core count and memory does not have an influence. The updates are up to date.

Now it's getting curious: I analyzed the trace and found out that the service is taking about 60 seconds for startup. Thus I've added a call to ReqestAdditionalTime(480000). But now the service takes slightly more than 480 seconds. The relation is obvious. The time is consumed in the following code section:

 var asyncResults = new List<IAsyncResult>();
 foreach (var host in myHosts)
   asyncResults.Add(host.BeginOpen(null, host));


  // wait until finished
  while (asyncResults.Count != 0)
  {
   IAsyncResult ar = asyncResults[0];
   if (!ar.IsCompleted) ar.AsyncWaitHandle.WaitOne(1000);
   if (ar.IsCompleted)
   {
        asyncResults.Remove(ar);
        var co = (ICommunicationObject)ar.AsyncState;

        try
        {
            co.EndOpen(ar);
        }
        catch (Exception ex)
        {
          ...
        }
   }
 }

Do you have any idea what's happening here?

Michael Stoll
  • 1,334
  • 3
  • 13
  • 35
  • So you're writing a service that requires network IO on startup. Why not put it on a background thread so your users don't have to wait? –  Feb 07 '10 at 21:06
  • Simply because then it is more difficult to detect, if the wcf hosts are open. The client currently checks if the service is in running state before it accesses the service. If the opening would use a seperate thread the only opportunity I know is to try access the service and wait for timeout or success. – Michael Stoll Feb 07 '10 at 21:36

1 Answers1

1

Hey, I found the resolution myself by doing some intensive Log-Research.

In the event log there were some services, which started AFTER the timeout of my service has been reached. As my service is running as a sepecial user, I could detect two services, which where acutally triggered by my own service. Thus I added those to the services dependencies and it works.

I wonder if there's a documentation, where the dependencies of wcf are listed. As reference here are the services, my service is dependen on:

  • http
  • RPCSS
  • CryptSvc
  • HTTPFilter
  • RasMan

Latter two where those causing the deadlock.

Michael Stoll
  • 1,334
  • 3
  • 13
  • 35