DigitalJedi805
DigitalJedi805

Reputation: 1460

Why won't this service start

I have a Windows Service that I'm having some problems getting working.

The pertinent functions are as follows:

( Edited to reflect current )

    static void Main()
    {
        if (Debugger.IsAttached)
        {
            ContinuumService Service = new ContinuumService();
            Service.Start(new Object[] { });

            while (true)
                Thread.Sleep(1);
        }
        else
        {
            ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[] 
            { 
                new ContinuumService() 
            };

            ServiceBase.Run(ServicesToRun);
        }
    }

    public ContinuumService()
    {
        InitializeComponent();
    }

    protected override void OnStart(string[] args)
    {
        base.OnStart(args);
    }

    protected override void OnStop()
    {
        base.OnStop();
    }

My installer is set to 'Allow service to interact with desktop' ( as I cannot seem to get the service to install without this ), and I know that the service is being installed - but is incapable of starting for some reason.

It's my understanding that a service Start command will execute OnStart and wait for that method to complete. Upon completion if the process is still running, the service reports running... If this is skewed please let me know.

The exact error I am getting back from the installer is 'Service '[display name]' ([name]) failed to start. Verify that you have sufficient privileges to start system services.'; and from the log that is generated behind the installer, I get an error 1920 with the same message.

In either case - I can't come up with a valid reason why this would be the case. Any advice would be great.

Upvotes: 2

Views: 399

Answers (2)

DigitalJedi805
DigitalJedi805

Reputation: 1460

Apparently there was an issue in my installer. After flipping options off, on, back off, inside out, and every other direction I could, I somehow corrupted the MSI, and had to rebuild it. A full wipe of the original installer project and a fresh build installed the service successfully. This was an issue in Advanced Installer 9.3

Thanks.

Upvotes: 0

Haney
Haney

Reputation: 34742

I believe your problem is both the loops and lack of base.OnStart() and base.OnStop() calls. You can start and stop a basic service with no loops, and it will run perpetually. Example basic service that literally does nothing:

public class ExampleService : ServiceBase
{
    private static void Main()
    {
        ServiceBase.Run(new[] { new ExampleService() });
    }

    public ExampleService()
    {
        // Name the Service
        ServiceName = "Example Service";
    }

    protected override void OnStart(string[] args)
    {
        base.OnStart(args);

       // Does nothing
    }

    protected override void OnStop()
    {
        base.OnStop();
    }
}

Try implementing this, see that it works, and incrementally add your logic and test.

Upvotes: 1

Related Questions