SMEAppHouse.Core.TopshelfAdapter 10.0.0

dotnet add package SMEAppHouse.Core.TopshelfAdapter --version 10.0.0
                    
NuGet\Install-Package SMEAppHouse.Core.TopshelfAdapter -Version 10.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SMEAppHouse.Core.TopshelfAdapter" Version="10.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SMEAppHouse.Core.TopshelfAdapter" Version="10.0.0" />
                    
Directory.Packages.props
<PackageReference Include="SMEAppHouse.Core.TopshelfAdapter" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SMEAppHouse.Core.TopshelfAdapter --version 10.0.0
                    
#r "nuget: SMEAppHouse.Core.TopshelfAdapter, 10.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SMEAppHouse.Core.TopshelfAdapter@10.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SMEAppHouse.Core.TopshelfAdapter&version=10.0.0
                    
Install as a Cake Addin
#tool nuget:?package=SMEAppHouse.Core.TopshelfAdapter&version=10.0.0
                    
Install as a Cake Tool

SMEAppHouse.Core.TopshelfAdapter

Overview

SMEAppHouse.Core.TopshelfAdapter is a library for handling Topshelf implemented Windows services. It provides base classes and abstractions for creating Windows services with lifecycle management, pause/resume functionality, and initialization control.

Target Framework: .NET 8.0
Namespace: SMEAppHouse.Core.TopshelfAdapter


Public Classes and Interfaces

1. TopshelfSocket<T>

Abstract base class for Topshelf service implementations.

Namespace: SMEAppHouse.Core.TopshelfAdapter

Implements: ITopshelfClientExt

Key Properties:

  • InitializationStatusEnum InitializationStatus - Current initialization status
  • bool IsPaused - Whether the service is paused
  • bool IsResumed - Whether the service is resumed
  • bool IsTerminated - Whether the service is terminated
  • ILogger Logger - Logger instance
  • RuntimeBehaviorOptions RuntimeBehaviorOptions - Runtime behavior configuration
  • Thread ServiceThread - The service thread

Key Events:

  • ServiceInitializedEventHandler OnServiceInitialized - Raised when service is initialized

Key Methods:

Control Methods
public void Resume()
public void Suspend()
public void Shutdown()
Abstract Methods (Must Implement)
protected abstract void ServiceInitializeCallback()
protected abstract void ServiceTerminateCallback()
protected abstract void ServiceActionCallback()

Constructor:

protected TopshelfSocket(RuntimeBehaviorOptions runtimeBehaviorOptions, ILogger logger)

Example:

using Microsoft.Extensions.Logging;
using SMEAppHouse.Core.TopshelfAdapter;
using SMEAppHouse.Core.TopshelfAdapter.Common;

public class MyService : TopshelfSocket<MyService>
{
    public MyService(RuntimeBehaviorOptions options, ILogger logger) 
        : base(options, logger)
    {
        OnServiceInitialized += (sender, e) =>
        {
            Logger.LogInformation("Service initialized");
        };
    }

    protected override void ServiceInitializeCallback()
    {
        // Initialize resources, connections, etc.
        Logger.LogInformation("Initializing service resources");
    }

    protected override void ServiceTerminateCallback()
    {
        // Cleanup resources
        Logger.LogInformation("Terminating service");
    }

    protected override void ServiceActionCallback()
    {
        // Main service logic - called repeatedly
        Logger.LogInformation($"Service action at {DateTime.Now}");
        // Your service work here
    }
}

// Usage
var options = new RuntimeBehaviorOptions
{
    MilliSecsDelay = 1000,
    IsBackground = true,
    LazyInitialization = false
};

var logger = LoggerFactory.Create(builder => builder.AddConsole()).CreateLogger<MyService>();
var service = new MyService(options, logger);
service.Resume();

2. ITopshelfClientExt

Extended interface for Topshelf clients.

Namespace: SMEAppHouse.Core.TopshelfAdapter

Inherits from: ITopshelfClient

Additional Properties:

  • Thread ServiceThread - The service thread

Additional Events:

  • ServiceInitializedEventHandler OnServiceInitialized - Service initialization event

3. ServiceInitializedEventArgs

Event arguments for service initialization.

Namespace: SMEAppHouse.Core.TopshelfAdapter

Example:

service.OnServiceInitialized += (sender, e) =>
{
    Console.WriteLine("Service initialized successfully");
};

Complete Usage Examples

Example 1: Basic Service Implementation

using Microsoft.Extensions.Logging;
using SMEAppHouse.Core.TopshelfAdapter;
using SMEAppHouse.Core.TopshelfAdapter.Common;

public class DataProcessingService : TopshelfSocket<DataProcessingService>
{
    private IDbConnection _connection;

    public DataProcessingService(RuntimeBehaviorOptions options, ILogger logger) 
        : base(options, logger)
    {
    }

    protected override void ServiceInitializeCallback()
    {
        Logger.LogInformation("Initializing database connection");
        _connection = CreateDatabaseConnection();
        Logger.LogInformation("Service initialized");
    }

    protected override void ServiceTerminateCallback()
    {
        Logger.LogInformation("Closing database connection");
        _connection?.Dispose();
        Logger.LogInformation("Service terminated");
    }

    protected override void ServiceActionCallback()
    {
        try
        {
            Logger.LogInformation("Processing data...");
            ProcessData();
        }
        catch (Exception ex)
        {
            Logger.LogError(ex, "Error in service action");
        }
    }

    private void ProcessData()
    {
        // Data processing logic
    }

    private IDbConnection CreateDatabaseConnection()
    {
        // Create connection
        return null; // Placeholder
    }
}

Example 2: Service with Lazy Initialization

public class LazyService : TopshelfSocket<LazyService>
{
    public LazyService(RuntimeBehaviorOptions options, ILogger logger) 
        : base(options, logger)
    {
    }

    protected override void ServiceInitializeCallback()
    {
        Logger.LogInformation("Lazy initialization triggered");
        // Initialize only when Resume() is called
    }

    protected override void ServiceTerminateCallback()
    {
        Logger.LogInformation("Service cleanup");
    }

    protected override void ServiceActionCallback()
    {
        Logger.LogInformation("Service running");
    }
}

// Usage with lazy initialization
var options = new RuntimeBehaviorOptions
{
    MilliSecsDelay = 5000,
    IsBackground = true,
    LazyInitialization = true // Don't initialize until Resume() is called
};

var service = new LazyService(options, logger);
// Service not initialized yet

// Initialize and start when ready
service.Resume(); // Now initialization happens

Key Features

  1. Lifecycle Management: Initialize, Resume, Suspend, Shutdown controls
  2. Thread Management: Background thread execution with configurable behavior
  3. Lazy Initialization: Optional delayed initialization
  4. Event-Driven: Initialization events for monitoring
  5. Logging Integration: Built-in ILogger support
  6. Console Ticker: Visual feedback during service execution

Dependencies

  • SMEAppHouse.Core.CodeKits
  • SMEAppHouse.Core.TopshelfAdapter.Common

Notes

  • Services run in background threads by default
  • ServiceActionCallback() is called repeatedly based on MilliSecsDelay
  • Use LazyInitialization = true to delay initialization until Resume() is called
  • Always implement cleanup in ServiceTerminateCallback()
  • The service thread is created but not started until Resume() is called (if lazy initialization is enabled)
  • Console ticker provides visual feedback with rotating characters

License

Copyright © Nephiora IT Solutions 2025

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on SMEAppHouse.Core.TopshelfAdapter:

Package Downloads
SMEAppHouse.Core.TopshelfAdapter.Scheduler

Library to handle Topshelf implemented queued service modules.

SMEAppHouse.Core.TopshelfAdapter.Aggregation

Library for handling collection of Topshelf implemented windows service.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
10.0.0 118 2/25/2026
9.0.9 159 11/29/2025
9.0.8 150 11/29/2025
9.0.7 155 11/29/2025
1.4.1906.15 1,355 6/12/2019
1.4.1906.14 1,233 6/9/2019
1.4.1811.9 1,317 11/9/2018
1.3.18073.3 1,121 11/8/2018

release notes