CMB.Services 1.1.1.46

A basic set of classes for creating a Windows service. Controller classes within this package allows the service to be run as an actual Windows service or as a console application.

Install-Package CMB.Services -Version 1.1.1.46
dotnet add package CMB.Services --version 1.1.1.46
<PackageReference Include="CMB.Services" Version="1.1.1.46" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CMB.Services --version 1.1.1.46
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Service Library Documentation

The Service Library will allow you to create a Windows service but also run it as a console application. What mode to run the service in shall be controlled by using either the ConsoleServiceController or WindowsServiceController classes. The service must be implemented in a class that derives from the Service class.

Implementing a Service

Below is a simple example of a service implementation:

class MyService : Service
{
    public MyService()
        : base("My Service Name")
    {
    }

    protected override void OnStart(string[] args)
    {
        // Service start up code goes here
    }

    protected override void OnStop()
    {
        // Service shut down code goes here
    }
}

Running as a Windows Service

To run the service as an actual Windows service, use the WindowsServiceController class to start the service.

var service = new MyService();
var controller = new WindowsServiceController();
controller.Run(service);

Running as a Console Application

To run the service as a console application, use the ConsoleServiceController class to start the service.

var service = new MyService();
var controller = new ConsoleServiceController();
controller.Run(service, ConsoleServiceOptions.WaitForStop);

Service Library Documentation

The Service Library will allow you to create a Windows service but also run it as a console application. What mode to run the service in shall be controlled by using either the ConsoleServiceController or WindowsServiceController classes. The service must be implemented in a class that derives from the Service class.

Implementing a Service

Below is a simple example of a service implementation:

class MyService : Service
{
    public MyService()
        : base("My Service Name")
    {
    }

    protected override void OnStart(string[] args)
    {
        // Service start up code goes here
    }

    protected override void OnStop()
    {
        // Service shut down code goes here
    }
}

Running as a Windows Service

To run the service as an actual Windows service, use the WindowsServiceController class to start the service.

var service = new MyService();
var controller = new WindowsServiceController();
controller.Run(service);

Running as a Console Application

To run the service as a console application, use the ConsoleServiceController class to start the service.

var service = new MyService();
var controller = new ConsoleServiceController();
controller.Run(service, ConsoleServiceOptions.WaitForStop);

Dependencies

This package has no dependencies.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.1.1.46 208 7/28/2018
1.0.0.23 786 12/3/2015