I have a windows service and I've written the code to run the task within the OnStart() event:
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);
}
}
The DoTask is a never-ending loop. It will stop only when the service is stopped.
But when I try to start the service, it waits a long time then gives me the below error:
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.
How to resolve it?