PnpObjectWatcher PnpObjectWatcher PnpObjectWatcher PnpObjectWatcher Class

Definition

Raises events to notify the client that a PnpObject has been added, updated, or removed from an enumerated collection of Pnp device objects in an incremental and asynchronous way.

public : sealed class PnpObjectWatcher : IPnpObjectWatcher
public sealed class PnpObjectWatcher : IPnpObjectWatcher
Public NotInheritable Class PnpObjectWatcher Implements IPnpObjectWatcher
// This class does not provide a public constructor.
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

An app calls Start to begin the search for devices. During this intial enumeration, the PnpObjectWatcher raises an Added event for each device that's found, until all devices are found. The PnpObjectWatcher raises an EnumerationCompleted event when the initial enumeration is complete, and continues to raise events if a device is added, updated, or removed.

The following diagram shows how the PnpObjectWatcher transitions between the states represented by DeviceWatcherStatus enumeration.

state diagram of DeviceWatcher states

The Start method can only be called when the PnpObjectWatcher is in the Created, Stopped or Aborted state. The Status property indicates the PnpObjectWatcher state. When re-starting the watcher, wait for the Stopped event before calling Start.

A call to Stop transitions the PnpObjectWatcher to the Stopping state and completes immediately. The watcher will transition to the Stopped state once all events that are already in the process of being raised have completed.

After calling Stop, apps may wait for the Stopped event if they need to know when the PnpObjectWatcher has stopped. Callers must wait for the Stopped event before they can call Start to restart the watcher. Callers may unsubscribe from events if they do not want to receive any additional events after Stop but do not want to wait for the Stopped event.

Properties

Status Status Status Status

The status associated with the asynchronous operation.

public : DeviceWatcherStatus Status { get; }
public DeviceWatcherStatus Status { get; }
Public ReadOnly Property Status As DeviceWatcherStatus
var deviceWatcherStatus = pnpObjectWatcher.status;

Methods

Start() Start() Start() Start()

Starts raising the events to inform the client that a PnpObject has been added, updated, or removed.

public : void Start()
public void Start()
Public Function Start() As void
pnpObjectWatcher.start();

Remarks

An app calls Start to begin the search for devices. During this intial enumeration, the PnpObjectWatcher raises an Added event for each device that's found, until all devices are found. The PnpObjectWatcher raises an EnumerationCompleted event when the initial enumeration is complete, and continues to raise events if a device is added, updated, or removed.

The Start method can only be called when the PnpObjectWatcher is in the Created, Stopped or Aborted state. The Status property indicates the PnpObjectWatcher state. When re-starting the watcher, wait for the Stopped event before calling Start.

The following diagram shows how the PnpObjectWatcher transitions between the states represented by DeviceWatcherStatus enumeration.

state diagram of DeviceWatcher states

Stop() Stop() Stop() Stop()

Stops raising the events to inform the client that a PnpObject has been added, updated, or removed.

public : void Stop()
public void Stop()
Public Function Stop() As void
pnpObjectWatcher.stop();

Remarks

To stop a search for devices, an app calls Stop.

This call transitions the PnpObjectWatcher to the Stopping state and completes immediately. The watcher will transition to the Stopped state once all events that are already in the process of being raised have completed.

Callers may wait for the Stopped event if they need to know when the PnpObjectWatcher has stopped. Callers must wait for the Stopped event before they can call Start to restart the watcher. Callers may unsubscribe from events if they do not want to receive any additional events after Stop but do not want to wait for the Stopped event.

The following diagram shows how the PnpObjectWatcher transitions between the states represented by DeviceWatcherStatus enumeration.

state diagram of DeviceWatcher states

Events

Added Added Added Added

Occurs when a PnpObject is added to the collection enumerated by the PnpObjectWatcher.

public : event TypedEventHandler Added<PnpObjectWatcher, PnpObject>
public event TypedEventHandler Added<PnpObjectWatcher, PnpObject>
Public Event TypedEventHandler Added( Of ( Of PnpObjectWatcher ), ( Of PnpObject ))
function onAdded(eventArgs){/* Your code */}


pnpObjectWatcher.addEventListener("added", onAdded);
pnpObjectWatcher.removeEventListener("added", onAdded);

EnumerationCompleted EnumerationCompleted EnumerationCompleted EnumerationCompleted

Occurs when the enumeration of Pnp device objects has been completed.

public : event TypedEventHandler EnumerationCompleted<PnpObjectWatcher, object>
public event TypedEventHandler EnumerationCompleted<PnpObjectWatcher, object>
Public Event TypedEventHandler EnumerationCompleted( Of ( Of PnpObjectWatcher ), ( Of object ))
function onEnumerationCompleted(eventArgs){/* Your code */}


pnpObjectWatcher.addEventListener("enumerationCompleted", onEnumerationCompleted);
pnpObjectWatcher.removeEventListener("enumerationCompleted", onEnumerationCompleted);

Removed Removed Removed Removed

Occurs when a PnpObject is removed from the collection enumerated by the PnpObjectWatcher.

public : event TypedEventHandler Removed<PnpObjectWatcher, PnpObjectUpdate>
public event TypedEventHandler Removed<PnpObjectWatcher, PnpObjectUpdate>
Public Event TypedEventHandler Removed( Of ( Of PnpObjectWatcher ), ( Of PnpObjectUpdate ))
function onRemoved(eventArgs){/* Your code */}


pnpObjectWatcher.addEventListener("removed", onRemoved);
pnpObjectWatcher.removeEventListener("removed", onRemoved);

Stopped Stopped Stopped Stopped

Occurs when the PnpObjectWatcher has stopped monitoring changes to the collection of Pnp device objects.

public : event TypedEventHandler Stopped<PnpObjectWatcher, object>
public event TypedEventHandler Stopped<PnpObjectWatcher, object>
Public Event TypedEventHandler Stopped( Of ( Of PnpObjectWatcher ), ( Of object ))
function onStopped(eventArgs){/* Your code */}


pnpObjectWatcher.addEventListener("stopped", onStopped);
pnpObjectWatcher.removeEventListener("stopped", onStopped);

Updated Updated Updated Updated

Occurs when the properties of a PnpObject in the collection enumerated by the PnpObjectWatcher are updated.

public : event TypedEventHandler Updated<PnpObjectWatcher, PnpObjectUpdate>
public event TypedEventHandler Updated<PnpObjectWatcher, PnpObjectUpdate>
Public Event TypedEventHandler Updated( Of ( Of PnpObjectWatcher ), ( Of PnpObjectUpdate ))
function onUpdated(eventArgs){/* Your code */}


pnpObjectWatcher.addEventListener("updated", onUpdated);
pnpObjectWatcher.removeEventListener("updated", onUpdated);