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
<PackageReference Include="SMEAppHouse.Core.TopshelfAdapter" Version="10.0.0" />
<PackageVersion Include="SMEAppHouse.Core.TopshelfAdapter" Version="10.0.0" />
<PackageReference Include="SMEAppHouse.Core.TopshelfAdapter" />
paket add SMEAppHouse.Core.TopshelfAdapter --version 10.0.0
#r "nuget: SMEAppHouse.Core.TopshelfAdapter, 10.0.0"
#:package SMEAppHouse.Core.TopshelfAdapter@10.0.0
#addin nuget:?package=SMEAppHouse.Core.TopshelfAdapter&version=10.0.0
#tool nuget:?package=SMEAppHouse.Core.TopshelfAdapter&version=10.0.0
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 statusbool IsPaused- Whether the service is pausedbool IsResumed- Whether the service is resumedbool IsTerminated- Whether the service is terminatedILogger Logger- Logger instanceRuntimeBehaviorOptions RuntimeBehaviorOptions- Runtime behavior configurationThread 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
- Lifecycle Management: Initialize, Resume, Suspend, Shutdown controls
- Thread Management: Background thread execution with configurable behavior
- Lazy Initialization: Optional delayed initialization
- Event-Driven: Initialization events for monitoring
- Logging Integration: Built-in ILogger support
- 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 onMilliSecsDelay- Use
LazyInitialization = trueto delay initialization untilResume()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 | Versions 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. |
-
net10.0
- SMEAppHouse.Core.CodeKits (>= 10.0.0)
- SMEAppHouse.Core.TopshelfAdapter.Common (>= 10.0.0)
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