Starting a windows service fails with error 1053

后端 未结 10 1339
逝去的感伤
逝去的感伤 2020-12-10 13:41

I have a windows service that is failing to start, giving an error \"Error 1053: The service did not respond to the start or control request in a timely fashion\".

相关标签:
10条回答
  • 2020-12-10 14:11

    This is a misleading error. It's probably an unhandled exception.

    Empty your OnStart() handler then try this in your constructor...

        public MainService()
        {
            InitializeComponent();
    
            try
            {
                // All your initialization code goes here.
    
                // For instance, my exception was caused by the lack of registry permissions
                ;
            }
            catch (Exception ex)
            {
                EventLog.WriteEntry("Application", ex.ToString(), EventLogEntryType.Error);
            }
        }
    

    Now check the EventLog on your system for your Application Error.

    0 讨论(0)
  • 2020-12-10 14:17

    I had that issue and the source of my problem was config file. I edited it in notepad and notepad added one special character which cause service not to run properly because config file was ruined. I saw that special character in notepadd++ and after delete it, service started to run successfully as previous did.

    0 讨论(0)
  • 2020-12-10 14:23

    One of the problems which may lead to this error is if windows service which needs to be deployed consists of some error i.e it may be simple authorization error or anything as in my case I have referenced some folders and files for logging which were not existing, but when provided the right path of those file and folders it solved my problem.

    0 讨论(0)
  • 2020-12-10 14:23

    In my case, the correct .NET framework was not installed on the server that I was installing the Windows service on.

    0 讨论(0)
  • 2020-12-10 14:24

    perhaps lacking some dependence, try this :
    - deregister your service
    - register again

    If fail at register means that lack an module.

    0 讨论(0)
  • 2020-12-10 14:30

    I ran through every post on this particular subject and none of the responses solved the problem, so I'm adding this response in case this helps someone else. Admittedly this only applies to a new service, not this specific case.

    I was writing a File listening service. As a console app, it worked perfectly. When I ran it as a service, I got the same error as above. What I didn't know (and many of the MSDN articles about services conveniently leave out) is that you need to have your class executed from within ServiceBase.Run( YourClassName());. Otherwise, your app executes and immediately terminates and because it terminated, you get the error above even if no error or exception occurred. Here is a link to an article about this. It actually discusses setting up your app for dual use - Console app and service: Create a combo command line / Windows service app

    0 讨论(0)
提交回复
热议问题