Error 1053: the service did not respond to the sta

2019-01-10 07:03发布

I have recently inherited a couple of applications that run as windows services, and I am having problems providing a gui (accessible from a context menu in system tray) with both of them.

The reason why we need a gui for a windows service is in order to be able to re-configure the behaviour of the windows service(s) without resorting to stopping/re-starting.

My code works fine in debug mode, and I get the context menu come up, and everything behaves correctly etc.

When I install the service via "installutil" using a named account (i.e., not Local System Account), the service runs fine, but doesn't display the icon in the system tray (I know this is normal behavior because I don't have the "interact with desktop" option).

Here is the problem though - when I choose the "LocalSystemAccount" option, and check the "interact with desktop" option, the service takes AGES to start up for no obvious reason, and I just keep getting

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.

Incidentally, I increased the windows service timeout from the default 30 seconds to 2 minutes via a registry hack (see http://support.microsoft.com/kb/824344, search for TimeoutPeriod in section 3), however the service start up still times out.

My first question is - why might the "Local System Account" login takes SOOOOO MUCH LONGER than when the service logs in with the non-LocalSystemAccount, causing the windows service time-out? what's could the difference be between these two to cause such different behavior at start up?

Secondly - taking a step back, all I'm trying to achieve, is simply a windows service that provides a gui for configuration - I'd be quite happy to run using the non-Local System Account (with named user/pwd), if I could get the service to interact with the desktop (that is, have a context menu available from the system tray). Is this possible, and if so how?

Any pointers to the above questions would be appreciated!

30条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-01-10 07:15

I also faced similar problem and found that there was issue loading assembly. I was receiving this error immediately when trying to start the service.

To quickly debug the issue, try to run service executable via command prompt using ProcDump http://technet.microsoft.com/en-us/sysinternals/dd996900. It shall provide sufficient hint about exact error.

http://bytes.com/topic/net/answers/637227-1053-error-trying-start-my-net-windows-service helped me quite a bit.

查看更多
我命由我不由天
3楼-- · 2019-01-10 07:16

My issue was due to target framework mentioned in windows service config was

<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
 </startup>

and my server in which I tried to install windows service was not supported for this .Net version.

Changing which , I could able to resolve the issue.

查看更多
孤傲高冷的网名
4楼-- · 2019-01-10 07:20

Install the debug build of the service and attach the debugger to the service to see what's happening.

查看更多
叼着烟拽天下
5楼-- · 2019-01-10 07:21

We have Log4Net configured to log to a database table. The table had grown so large that the service was timing out trying to log messages.

查看更多
欢心
6楼-- · 2019-01-10 07:22

In service class within OnStart method don't do huge operation, OS expect short amount of time to run service, run your method using thread start:

protected override void OnStart(string[] args)
{
    Thread t = new Thead(new ThreadStart(MethodName)); // e.g.
    t.Start();
}
查看更多
相关推荐>>
7楼-- · 2019-01-10 07:22

Once try to run your exe file. I had the same problem, but when I ran it direct by double click on the exe file, I got a message about .Net framework version, because I was released the service project with a framework which it wasn't installed on target machine.

查看更多
登录 后发表回答