jwa*_*zko 13 .net windows-services windows-server-2008-r2
这个问题似乎被广泛讨论,但我在特定情况下找到解决方案时遇到了问题.
我的服务设置为在Local System帐户下运行.在我的第一台安装了Windows 7 SP1(64位)的计算机上,一切都按预期工作.但是,在我尝试使用Windows Server 2008 R2 SP1(64位)在我的第二台机器上启动服务之后,甚至没有一秒钟通过,我正面临着这个恼人的错误:
Windows could not start the ProService service on Local Computer
Error 1053: The service did not respond to the start or control request in a timely fashion
Run Code Online (Sandbox Code Playgroud)
该System Log显示2项:
The ProService service failed to start due to the following error:
The service did not respond to the start or control request in a timely fashion.
Run Code Online (Sandbox Code Playgroud)
和:
A timeout was reached (30000 milliseconds) while waiting for the ProService service to connect.
Run Code Online (Sandbox Code Playgroud)
实施如下:
Program.cs中:
static void Main()
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomainUnhandledException;
ServiceBase.Run(new ServiceBase[] { new ProService() });
}
static void CurrentDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
if (e != null && e.ExceptionObject != null)
{
Logger.Record(e.ExceptionObject);
}
}
Run Code Online (Sandbox Code Playgroud)
ProService.cs:
public ProService()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
try
{
RequestAdditionalTime(10000);
FireStarter.Instance.Execute();
}
catch (Exception e)
{
Logger.Record(e);
throw;
}
}
Run Code Online (Sandbox Code Playgroud)
该OnStart方法只是启动一个新线程,因此执行几乎没有时间加载.RequestAdditionalTime为了以防万一,我使用了陈述 - 拒绝这件事作为我问题的根源.此外,正如您所看到的,我正在处理所有异常,但在启动期间没有异常写入我的自定义服务事件日志(顺便说一句:日志记录正在第一台win7计算机上运行).如何调查发生了什么?
jwa*_*zko 10
我通过几个步骤弄清楚了发生了什么:
OnStart从服务方法中完成的.我比较了2个配置 - 来自服务,原始来自控制台应用程序.结果我发现了一些差异.其中,有这样一个条目 - 问题的根源(删除后,一切正常):
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
Run Code Online (Sandbox Code Playgroud)所以基本上我有过时的配置文件.之前的服务是在.NET 4.5下编译的,然后我将框架更改为4.0并将文件部署到服务器,但是保留了以前的配置文件(我已经更改了目标框架,因为我的开发机器有.NET 4.5,而服务器则是不).我不会想到显示的行会在没有任何合理信息的情况下隐藏所有问题,这可能有助于跟踪混乱.
| 归档时间: |
|
| 查看次数: |
47384 次 |
| 最近记录: |