Oakrey.Applications.UsbNotifying 7.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Oakrey.Applications.UsbNotifying --version 7.0.0
                    
NuGet\Install-Package Oakrey.Applications.UsbNotifying -Version 7.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="Oakrey.Applications.UsbNotifying" Version="7.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Oakrey.Applications.UsbNotifying" Version="7.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Oakrey.Applications.UsbNotifying" />
                    
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.UsbNotifying --version 7.0.0
                    
#r "nuget: Oakrey.Applications.UsbNotifying, 7.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 Oakrey.Applications.UsbNotifying@7.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=Oakrey.Applications.UsbNotifying&version=7.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Oakrey.Applications.UsbNotifying&version=7.0.0
                    
Install as a Cake Tool

Oakrey.Applications.UsbNotifying

A Windows-only .NET library that monitors USB device arrival and removal events through the Windows PnP notification API and exposes them as an IObservable<UsbEventArgs> stream.

Features

  • Wraps DeviceNotificationListener from Nefarius.Utilities.DeviceManagement.
  • Exposes USB events through IUsbNotifyingService.
  • Uses a synchronized ReplaySubject<UsbEventArgs>(1); late subscribers receive the latest event and concurrent callbacks are serialized.
  • Logs device status, VID, and PID with placeholder-based Oakrey.Log messages without exposing a unique serial number.
  • Contains callback exceptions so they cannot escape into the native listener.
  • Provides idempotent IDisposable cleanup and completes observers during shutdown.

Architecture

classDiagram
    IObservable~UsbEventArgs~ <|-- IUsbNotifyingService
    IUsbNotifyingService <|.. UsbNotifyingService
    IDisposable <|.. UsbNotifyingService
    UsbNotifyingService --> DeviceNotificationListener : wraps
    UsbNotifyingService --> ReplaySubject~UsbEventArgs~ : publishes through

Public API

public interface IUsbNotifyingService : IObservable<UsbEventArgs> { }

public sealed class UsbNotifyingService : IUsbNotifyingService, IDisposable
{
    public UsbNotifyingService();
    public IDisposable Subscribe(IObserver<UsbEventArgs> observer);
    public void Dispose();
}

UsbEventArgs is provided by Oakrey.Usb and contains:

  • DeviceInfo.VID: vendor identifier
  • DeviceInfo.PID: product identifier
  • DeviceInfo.DeviceId: symbolic link or serial number
  • UsbDeviceChangeStatus: Inserted or Removed

Requirements

  • .NET 10 for Windows
  • Nefarius.Utilities.DeviceManagement 5.2.x
  • Oakrey.Log.Abstractions 3.0.x
  • Oakrey.Usb 3.2.x
  • System.Reactive 6.1.x

Installation

dotnet add package Oakrey.Applications.UsbNotifying
Install-Package Oakrey.Applications.UsbNotifying

Usage

Manual instantiation

using Oakrey.Applications.UsbNotifying;

using UsbNotifyingService service = new();
using IDisposable subscription = service.Subscribe(usbEvent =>
{
    Console.WriteLine(
        $"{usbEvent.UsbDeviceChangeStatus}: VID={usbEvent.DeviceInfo.VID} PID={usbEvent.DeviceInfo.PID}");
});

// Keep the application alive while notifications are required.

Dependency injection

services.AddSingleton<IUsbNotifyingService, UsbNotifyingService>();
public sealed class MyHandler : IDisposable
{
    private readonly IDisposable subscription;

    public MyHandler(IUsbNotifyingService usbService)
    {
        subscription = usbService.Subscribe(usbEvent =>
        {
            if (usbEvent.UsbDeviceChangeStatus == UsbDeviceChangeStatus.Inserted)
            {
                // Handle device arrival.
            }
        });
    }

    public void Dispose()
    {
        subscription.Dispose();
    }
}

Development notes

  • The service must run on Windows because DeviceNotificationListener uses Windows PnP APIs.
  • ReplaySubject(1) replays the most recent event to a new subscriber.
  • Subject access is synchronized to protect state when PnP callbacks arrive concurrently.
  • Parsing and observer failures are logged and contained at the listener callback boundary.
  • Always dispose the service, or its DI container, before application exit.

License

MIT. Copyright (c) Oakrey 2016-present.

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 (1)

Showing the top 1 NuGet packages that depend on Oakrey.Applications.UsbNotifying:

Package Downloads
Oakrey.Applications.Ohm.CAN

Service layer library for managing CAN bus hardware devices and channels. Provides device discovery, connection lifecycle management, reactive IObservable streams for received frames and status changes, per-channel transmit, USB hot-plug detection, and persistent JSON configuration.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
7.0.1 106 8/6/2026
7.0.0 123 7/20/2026
2.0.7 116 7/8/2026
2.0.6 126 7/3/2026
2.0.5 148 5/22/2026
2.0.3 113 5/15/2026
2.0.2 133 3/13/2026
2.0.1 122 3/11/2026
1.0.0 390 4/22/2025