Oakrey.Applications.Windows
7.0.2
dotnet add package Oakrey.Applications.Windows --version 7.0.2
NuGet\Install-Package Oakrey.Applications.Windows -Version 7.0.2
<PackageReference Include="Oakrey.Applications.Windows" Version="7.0.2" />
<PackageVersion Include="Oakrey.Applications.Windows" Version="7.0.2" />
<PackageReference Include="Oakrey.Applications.Windows" />
paket add Oakrey.Applications.Windows --version 7.0.2
#r "nuget: Oakrey.Applications.Windows, 7.0.2"
#:package Oakrey.Applications.Windows@7.0.2
#addin nuget:?package=Oakrey.Applications.Windows&version=7.0.2
#tool nuget:?package=Oakrey.Applications.Windows&version=7.0.2
Oakrey.Applications.Windows
A .NET 10 Windows library for programmatic management of OS processes and Windows services. Both managers run as BackgroundService hosted services and expose reactive status streams via System.Reactive, with built-in Oakrey.Log and Oakrey.Telemetry integration.
Main features
- Process management - start an existing executable without shell interpretation or kill all instances by name and wait for their exit; observe running-state changes via
IObservable<ProcessInfo>. - Service lifecycle - start, stop, pause, continue, and restart any Windows service asynchronously.
- Supervised service restart -
ServiceManagerserially monitors supervised services and automatically restores stopped or paused services without overlapping callbacks. - Reactive status stream -
StatusChangeemits state changes and replays only the latest state to late subscribers, preventing unbounded history retention. - Dual cancellation API - every operation accepts either a
CancellationTokenor aTimeSpan; cancellation and operational failures are logged and propagated to callers. - Async-friendly
ServiceController-ServiceControllerExtensions.WaitForStatusAsyncpollsServiceControllerwithout blocking a thread. - Logging and telemetry - all operations are traced with
Oakrey.Telemetryand use placeholder-basedOakrey.Logmessages without executable paths.
Architecture
classDiagram
class ManagerBase~TManaged_TSettings~ {
#TSettings _settings
#ReplaySubject~TManaged~ _serviceStatus
#List~TManaged~ InfoCache
#Lock CacheLock
+IObservable~TManaged~ StatusChange
}
class IProcessManager {
+IObservable~ProcessInfo~ StatusChange
+StartProcess(path, CancellationToken)
+StartProcess(path, TimeSpan)
+KillProcessByName(name, CancellationToken)
+KillProcessByName(name, TimeSpan)
}
class ProcessManager {
+UpdateServiceStatus()
}
class IProcessManagerSettings {
+int Interval
+List~string~ ObservedProcess
}
class IServiceManager {
+IObservable~ServiceInfo~ StatusChange
+StartService(name, CancellationToken)
+StopService(name, CancellationToken)
+PauseService(name, CancellationToken)
+ContinueService(name, CancellationToken)
+RestartService(name, CancellationToken)
}
class ServiceManager {
+RestartNotRunningSupervisedServices()
}
class IServiceManagerSettings {
+int Interval
+List~string~ ObservedServices
+List~string~ SupervisedServices
}
ManagerBase <|-- ProcessManager
ManagerBase <|-- ServiceManager
IProcessManager <|.. ProcessManager
IServiceManager <|.. ServiceManager
ProcessManager o-- IProcessManagerSettings
ServiceManager o-- IServiceManagerSettings
Key types
| Type | Description |
|---|---|
ManagerBase<TManaged, TSettings> |
Abstract BackgroundService base; owns the bounded reactive subject and synchronized state cache. |
IProcessManager / ProcessManager |
Manages OS processes; polls every Interval seconds for state changes. |
IServiceManager / ServiceManager |
Manages Windows services; supports supervised auto-restart. |
IProcessManagerSettings |
Configures polling interval and the list of observed processes. |
IServiceManagerSettings |
Configures polling interval, observed services, and supervised services. |
ServiceControllerExtensions |
Adds WaitForStatusAsync to ServiceController for async-friendly status waiting. |
Requirements
- .NET 10 (Windows)
- Windows OS (uses
System.ServiceProcessandSystem.Diagnostics.Process) - Direct dependencies:
Microsoft.Extensions.Hosting.Abstractions10.0.10,Oakrey.ProcessesAndServices2.0.2,System.ServiceProcess.ServiceController10.0.10,System.Reactive6.1.0,Oakrey.Log.Abstractions3.0.0, andOakrey.Telemetry2.0.1
Installation
.NET CLI
dotnet add package Oakrey.Applications.Windows
Package Manager Console
Install-Package Oakrey.Applications.Windows
NuGet Package Manager
Search for Oakrey.Applications.Windows in Visual Studio under
Tools > NuGet Package Manager > Manage NuGet Packages for Solution.
Configuration
Implement IProcessManagerSettings and IServiceManagerSettings to supply your settings:
public class MyProcessSettings : IProcessManagerSettings
{
public int Interval => 5;
public List<string> ObservedProcess => ["notepad", "myapp"];
}
public class MyServiceSettings : IServiceManagerSettings
{
public int Interval => 10;
public List<string> ObservedServices => ["MyService"];
public List<string> SupervisedServices => ["MyService"];
}
Example usage
Register both managers as hosted services in a .NET generic host:
HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);
builder.Services.AddSingleton<IProcessManagerSettings, MyProcessSettings>();
builder.Services.AddSingleton<IServiceManagerSettings, MyServiceSettings>();
builder.Services.AddSingleton<IProcessManager, ProcessManager>();
builder.Services.AddSingleton<IServiceManager, ServiceManager>();
builder.Services.AddHostedService(sp => (ProcessManager)sp.GetRequiredService<IProcessManager>());
builder.Services.AddHostedService(sp => (ServiceManager)sp.GetRequiredService<IServiceManager>());
IHost host = builder.Build();
Subscribe to reactive status changes:
IProcessManager processManager = host.Services.GetRequiredService<IProcessManager>();
processManager.StatusChange.Subscribe(info =>
Console.WriteLine($"{info.Name} running: {info.Running}"));
IServiceManager serviceManager = host.Services.GetRequiredService<IServiceManager>();
serviceManager.StatusChange.Subscribe(info =>
Console.WriteLine($"{info.Name} status: {info.Status}"));
await host.RunAsync();
Manually control a service with a timeout:
IServiceManager svc = host.Services.GetRequiredService<IServiceManager>();
await svc.StopService("MyService", TimeSpan.FromSeconds(15));
await svc.StartService("MyService", TimeSpan.FromSeconds(15));
Development notes
- Both
ProcessManagerandServiceManagerextendBackgroundService; register them withAddHostedServiceso the host controls their lifetime andStopAsync/Disposeare called correctly. ObservedServicescontrols which services emitStatusChangeevents.SupervisedServicesadditionally triggers automatic restart viaRestartNotRunningSupervisedServices.- Both managers use their configured positive
Intervalin seconds and run a cancellation-awarePeriodicTimerloop; invalid intervals fail during startup. ServiceControllerExtensions.WaitForStatusAsyncpolls every 250 ms. Public manager operations always receive a cancellation token or create one from the requested timeout.- The
ReplaySubject(1)inManagerBasereplays only the last known state to a late subscriber and is completed and disposed with the hosted service. StartProcessrequires an existing executable file and setsUseShellExecute = false; arguments and shell documents are intentionally not accepted by the current interface.
License
MIT - Copyright (c) Oakrey 2016-2025. See LICENSE for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0-windows7.0 is compatible. |
-
net10.0-windows7.0
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.12)
- Oakrey.Log.Abstractions (>= 3.0.0)
- Oakrey.ProcessesAndServices (>= 2.0.4)
- Oakrey.Telemetry (>= 2.0.1)
- System.Reactive (>= 7.0.0)
- System.ServiceProcess.ServiceController (>= 10.0.12)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.