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
                    
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="Oakrey.Applications.Windows" Version="7.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Oakrey.Applications.Windows" Version="7.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Oakrey.Applications.Windows" />
                    
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 Oakrey.Applications.Windows --version 7.0.2
                    
#r "nuget: Oakrey.Applications.Windows, 7.0.2"
                    
#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 Oakrey.Applications.Windows@7.0.2
                    
#: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=Oakrey.Applications.Windows&version=7.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Oakrey.Applications.Windows&version=7.0.2
                    
Install as a Cake Tool

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 - ServiceManager serially monitors supervised services and automatically restores stopped or paused services without overlapping callbacks.
  • Reactive status stream - StatusChange emits state changes and replays only the latest state to late subscribers, preventing unbounded history retention.
  • Dual cancellation API - every operation accepts either a CancellationToken or a TimeSpan; cancellation and operational failures are logged and propagated to callers.
  • Async-friendly ServiceController - ServiceControllerExtensions.WaitForStatusAsync polls ServiceController without blocking a thread.
  • Logging and telemetry - all operations are traced with Oakrey.Telemetry and use placeholder-based Oakrey.Log messages 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.ServiceProcess and System.Diagnostics.Process)
  • Direct dependencies: Microsoft.Extensions.Hosting.Abstractions 10.0.10, Oakrey.ProcessesAndServices 2.0.2, System.ServiceProcess.ServiceController 10.0.10, System.Reactive 6.1.0, Oakrey.Log.Abstractions 3.0.0, and Oakrey.Telemetry 2.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 ProcessManager and ServiceManager extend BackgroundService; register them with AddHostedService so the host controls their lifetime and StopAsync/Dispose are called correctly.
  • ObservedServices controls which services emit StatusChange events. SupervisedServices additionally triggers automatic restart via RestartNotRunningSupervisedServices.
  • Both managers use their configured positive Interval in seconds and run a cancellation-aware PeriodicTimer loop; invalid intervals fail during startup.
  • ServiceControllerExtensions.WaitForStatusAsync polls every 250 ms. Public manager operations always receive a cancellation token or create one from the requested timeout.
  • The ReplaySubject(1) in ManagerBase replays only the last known state to a late subscriber and is completed and disposed with the hosted service.
  • StartProcess requires an existing executable file and sets UseShellExecute = 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 Compatible and additional computed target framework versions.
.NET net10.0-windows7.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
7.0.2 106 9/21/2026
7.0.1 114 8/6/2026
7.0.0 123 7/20/2026
2.0.6 123 7/8/2026
2.0.5 120 7/3/2026
2.0.4 122 5/22/2026