Oakrey.Applications.UsbNotifying 2.0.6

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

Oakrey.Applications.UsbNotifying

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

Features

  • Wraps DeviceNotificationListener from Nefarius.Utilities.DeviceManagement � no raw Win32 interop required.
  • Exposes USB events as IObservable<UsbEventArgs> via IUsbNotifyingService.
  • Backed by a ReplaySubject<UsbEventArgs>(1) � late subscribers receive the most recent event immediately.
  • Logs device VID, PID, and serial number on every connect/disconnect via Oakrey.Log.
  • Implements IDisposable � properly unregisters listeners and disposes subjects.

Architecture

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

Public API

// Service interface � subscribe to receive USB events
public interface IUsbNotifyingService : IObservable<UsbEventArgs> { }

// Concrete service � register with DI or instantiate directly
public sealed class UsbNotifyingService : IUsbNotifyingService, IDisposable
{
    public UsbNotifyingService();
    public IDisposable Subscribe(IObserver<UsbEventArgs> observer);
    public void Dispose();
}

UsbEventArgs is provided by Oakrey.Usb and carries:

  • DeviceInfo.VID � vendor identifier
  • DeviceInfo.PID � product identifier
  • DeviceInfo.DeviceId � symbolic link / serial number
  • UsbDeviceChangeStatusINSERTED or REMOVED

Requirements

  • .NET 10 (Windows)
  • Nefarius.Utilities.DeviceManagement 5.2.x
  • Oakrey.Usb 3.0.x
  • Oakrey.Log 2.0.x
  • System.Reactive 6.1.x

Installation

.NET CLI

dotnet add package Oakrey.Applications.UsbNotifying

Package Manager Console

Install-Package Oakrey.Applications.UsbNotifying

NuGet Package Manager UI

Search for Oakrey.Applications.UsbNotifying in Visual Studio under Tools > NuGet Package Manager > Manage NuGet Packages for Solution.

Usage

Manual instantiation

using Oakrey.Applications.UsbNotifying;

await using UsbNotifyingService service = new();

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

// Keep the application alive; dispose subscription when done.
subscription.Dispose();

Dependency injection

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

    public MyHandler(IUsbNotifyingService usbService)
    {
        subscription = usbService.Subscribe(e =>
        {
            if (e.UsbDeviceChangeStatus == UsbDeviceChangeStatus.INSERTED)
            {
                // handle device arrival
            }
        });
    }
}

Development notes

  • The service must run on Windows � DeviceNotificationListener calls Win32 PnP APIs. The target framework net10.0-windows enforces this at build time.
  • ReplaySubject(1) means any subscriber that registers after the last event still receives it immediately. Use a fresh Subject<T> instead if that behaviour is undesirable.
  • DeviceNotificationListener.StartListen is called for DeviceInterfaceIds.UsbDevice. To monitor a different device class, derive from or wrap UsbNotifyingService and pass a different Guid to StartListen.
  • Always dispose the service (or the DI container) before application exit to unregister the PnP listener cleanly.

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.Abstractions

Shared contracts and robust lifecycle base classes for Oakrey hardware channels, devices, and device services.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
7.0.1 199 8/6/2026
7.0.0 129 7/20/2026
2.0.7 118 7/8/2026
2.0.6 128 7/3/2026
2.0.5 150 5/22/2026
2.0.3 115 5/15/2026
2.0.2 136 3/13/2026
2.0.1 124 3/11/2026
1.0.0 393 4/22/2025