locked
windows service did not respond to the start or control request in a timely fashion RRS feed

  • Question

  • Hi,

    I have created a simple windows service (using topshelf) which writes text to event log . Service works perfectly from Visual Studio Express 2012 but after installing it an clicking on start it gives me an error :1053 The service did not respond to the start or control request in a timely fashion. After that status of the service is start pending. I tried to run the service both as local system (with or without desktop cooperation) and user with admin privileges.
     
    I have already tried solutions from other topics but nothing seems to useful.

    Below you may see the code :

        public class Test
        {
            public void Start()
            {
                try
                {
                    Console.WriteLine("Start");
                    Execute();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
    
            public void Stop()
            {
                try
                {
                    Console.WriteLine("Stop  ");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
    
            public void Execute()
            {
                EventLog _log = new EventLog();
                _log.Source = "123Test";
    
                try
                {
                    while (true)
                    {
                        _log.WriteEntry("sleeping ..." + System.DateTime.Now.ToString());
                        Thread.Sleep(5000); 
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("error: " + e.Message.ToString());
                }
            }
        }
        
        public class Program
        {
            public static void Main()
            {
                try
                {
                    HostFactory.Run(x =>
                    {
                        x.Service<Test>(s =>
                        {
                            s.ConstructUsing(name => new Test());
                            s.WhenStarted(test => test.Start());
                            s.WhenStopped(test => test.Stop());
                        });
    
                        x.RunAsLocalSystem();
                        x.SetDisplayName("123Test");
                        x.SetServiceName("123Test");
                    });
                }
                catch (Exception ex)
                {
                    EventLog.WriteEntry("123Test", ex.ToString(), System.Diagnostics.EventLogEntryType.Error);
                }
            }
        }
    I would appreciate any suggestion that may lead to solving this problem.

    Edit: (OS - Win7)
    • Edited by BukajResalg Thursday, May 16, 2013 10:06 AM
    • Moved by Santosh Bhandarkar Thursday, May 16, 2013 11:29 AM Moved from Server General forum
    Thursday, May 16, 2013 10:02 AM

Answers

All replies