2013-10-25 50 views
3

我们使用TopShelf托管服务。在开始服务之前,我们正在进行数据库调用以加载大量数据。正因为如此,在启动该服务,我们得到以下错误:顶部框架超时问题

Start Service failed with return code '[7] ServiceRequestTimeout 

我们用下面的代码来启动服务:

HostFactory.Run(x => 
      { 
       x.Service<AppService>(s => 
       { 
        s.ConstructUsing(name => new AppService(s_resolver, baseAddress, resolver)); 
        s.WhenStarted(svc => svc.Start()); 
        s.WhenStopped(svc => svc.Stop()); 
        s.WhenShutdown(svc => svc.Shutdown()); 
       }); 

       x.EnableShutdown(); 
       x.RunAsLocalService(); 
       x.StartAutomatically(); 
       x.SetDisplayName("Application Host"); 
       x.SetDescription("Application Host"); 
      }); 

如果我尝试使用Visual Studio推出的服务,服务运行良好。但是,当通过TopShelf托管服务时,我得到了超时错误。

我也试过使用hostControl.RequestAdditionalTime(TimeSpan.FromSeconds(300)) ,但即使添加了额外的超时时间后,我仍无法解决问题。请提供您的建议。

+1

topshelf-4给你x.SetStartT imeOut(Timespan)和x.SetStopTimeout(TimeSpan) – BozoJoe

回答

7

HostControl.RequestAdditionalTime未能声明的文档是您只能要求最多60或120秒。否则,它会忽略您的请求。

它出色的记录绝对没有在那里,我所知道的:(如果你发现它记录了一些地方,请让我知道。

+0

谢谢你的回复Travis。我尝试将120设置为AdditionalTime,但即使这样也行不通。 – SharpCoder

+0

你试过60吗? – Travis

+0

nope。我会检查并让你知道:)但是我确实试过了120,并没有发挥作用 – SharpCoder

0

这里是龙

从TopShelf

void HostControl.RequestAdditionalTime(TimeSpan timeRemaining) 
    { 
     _log.DebugFormat("Requesting additional time: {0}", timeRemaining); 

     RequestAdditionalTime((int)timeRemaining.TotalMilliseconds); 
    } 

这里是从ServiceBase JustDecompile

/// <summary>Requests additional time for a pending operation.</summary> 
    /// <param name="milliseconds">The requested time in milliseconds.</param> 
    /// <exception cref="T:System.InvalidOperationException">The service is not in a pending state.</exception> 
    [ComVisible(false)] 
    public void RequestAdditionalTime(int milliseconds) 
    { 
     unsafe 
     { 
      fixed (NativeMethods.SERVICE_STATUS* sERVICESTATUSPointer = &this.status) 
      { 
       if (this.status.currentState != 5 && this.status.currentState != 2 && this.status.currentState != 3 && this.status.currentState != 6) 
       { 
        throw new InvalidOperationException(Res.GetString("NotInPendingState")); 
       } 
       this.status.waitHint = milliseconds; 
       this.status.checkPoint = this.status.checkPoint + 1; 
       NativeMethods.SetServiceStatus(this.statusHandle, sERVICESTATUSPointer); 
      } 
     } 
    } 
+0

我无法赞成,因为我对API一无所知,但LOL @“这里是龙”。 –