Brows.Sys.Win32.Windows 1.0.0

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

Brows.Sys.Win32.Windows

A WPF adapter that turns Windows device-change messages into Brows system notifications. The package targets net10.0-windows with WPF enabled and references Brows.Sys.Composition and Brows.Sys.Win32.

Installation

dotnet add package Brows.Sys.Win32.Windows

Use a Windows application targeting net10.0-windows. A WPF host should have UseWpf enabled. The package includes the core contracts, composition layer, and native backend through its dependencies.

Composition setup

The adapter's factory is internal and implements the public ISystemMessengerFactory contract. Configure your Brows.Composition host to discover both the Brows.Sys.Composition and Brows.Sys.Win32.Windows assemblies. Initialize the host, then obtain the message set:

using Brows;
using Brows.Sys;

var messengerSet = Imports.Find<ISystemMessengerSet>(
    throwIfNotFound: true,
    throwIfNotReady: true);

There is no public Win32WindowsMessengerFactory constructor for application code. Composition supplies the implementation.

Listen to a window

Start reading from the UI thread after the WPF window's SourceInitialized event, when its native handle exists. Supply a cancellation token that is canceled when the window closes.

using Brows.Sys;
using Brows.Sys.Messages.DeviceMessages;
using Brows.Sys.Messages.DeviceMessages.Devices;
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;

static async Task WatchDevicesAsync(
    ISystemMessengerSet messengerSet,
    Window window,
    CancellationToken cancellationToken) {
    try {
        await foreach (var message in messengerSet.ReadAllSystemMessages(window, cancellationToken)) {
            if (message is DeviceChange { Device: VolumeDevice volume } change) {
                Console.WriteLine($"{change.DeviceChangeKind}: {volume.VolumeName} ({volume.VolumeFlag})");
            }
        }
    }
    catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested) {
    }
}

This example receives an already initialized message set; initialize composition once in the host rather than for every window. If consumption runs on a background context, marshal UI changes to window.Dispatcher.

Accepted windows and ownership

  • The factory accepts a WPF Window with an existing native handle, or a boxed nint whose handle belongs to a live HwndSource in the application. A Window resolves its handle on the window's dispatcher, so both forms work from a background thread; a window whose dispatcher is shutting down produces no messenger.
  • Arbitrary native HWNDs without a WPF source are unsupported. A zero handle or a handle without a live WPF source produces no messenger. Hook attachment also declines a source that is disposed or whose dispatcher is shutting down.
  • Hook attachment and removal run on the source's dispatcher. Dispose direct factory results when finished; the composition stream disposes its own results when enumeration ends.
  • Disposal unregisters owned interface notifications and detaches this listener's hook. It preserves the borrowed window source and is safe to repeat after the owner closes the source.
  • Closing the window does not itself complete the message stream. The host should cancel its reader and await the reading task's completion.

Interface registration and cleanup

Every messenger automatically registers the disk, volume, and Windows Portable Device interface classes using RegisterDeviceNotificationW. Registration is performed on the source dispatcher. Port and volume broadcasts need no additional registration. Basic broadcasts require a top-level receiver window.

Creation fails with a Win32Exception if a registration fails. Partial registrations and hooks are rolled back while preserving the original error. Cancellation during initialization uses the same rollback. The composition reader propagates these failures, and the sample displays them in its existing error/status area.

Registrations are owned by safe handles and are released on listener disposal, source closure, or dispatcher shutdown. Repeated cleanup is safe and never disposes the borrowed WPF source. Window closure still does not complete the composition stream; cancel the reader as before.

The profile is fixed. There is no subscription-configuration, device-enumeration, metadata-enrichment, or removal-veto API.

Notification scope

The adapter forwards device-tree notifications and the five supported arrival/removal events decoded by Brows.Sys.Win32. Port and interface events include copied native identities; device-tree events identify no individual device. A volume notification affecting multiple drives produces one managed message for each drive. Other recognized device types can have a null Device payload.

The hook leaves Windows' normal message processing in place. Neither the async stream nor its message records provide a way to approve or deny native queries, including device-removal requests. File/folder changes, Shell notifications, clipboard changes, and other window-message categories are not currently published by this adapter.

License and source

MIT license. Source repository.

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
1.1.0 84 10/8/2026
1.0.0 98 10/8/2026