我有一个 Windows 服务,并且我已经编写了在 OnStart() 事件中运行任务的代码:
protected override void OnStart(string[] args)
{
this.DoTask();
}
private void DoTask()
{
Task task1 = Task.Factory.StartNew(() => this.OriginalFileProcessor.StartPolling());
try
{
Task.Wait(task1);
}
catch (Exception ex)
{
this.Log.Error("Failed running the task", ex);
}
}
DoTask 是一个永无止境的循环。只有在服务停止时才会停止。
但是当我尝试启动服务时,它会等待很长时间,然后给我以下错误:
Windows could not start the ... service on Local Computer.
Error 1053: The service did not respond to the start or control request in a timely fashion.
如何解决?