Why does my .NET service start really slow on a XP boot

那年仲夏 提交于 2019-12-22 00:13:29

问题


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?


回答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.



来源:https://stackoverflow.com/questions/2218029/why-does-my-net-service-start-really-slow-on-a-xp-boot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!