Freigeben über


DeviceInformation.CreateWatcher Method

Definition

Overloads

CreateWatcher()

Creates a DeviceWatcher for all devices.

CreateWatcher(String)

Creates a DeviceWatcher for devices matching the specified Advanced Query Syntax (AQS) string.

CreateWatcher(DeviceClass)

Creates a DeviceWatcher for devices matching the specified DeviceClass.

CreateWatcher(String, IIterable<String>)

Creates a DeviceWatcher for devices matching the specified Advanced Query Syntax (AQS) string and the specified collection of properties.

CreateWatcher(String, IIterable<String>, DeviceInformationKind)

Creates a DeviceWatcher for devices matching the specified Advanced Query Syntax (AQS) string, the specified collection of properties, and the kind of devices.

CreateWatcher(String, IIterable<String>, DeviceInformationKind, IDeviceEnumerationSettings)

Creates a DeviceWatcher for devices matching the specified Advanced Query Syntax (AQS) string, the specified collection of properties, the kind of device, and the settings.

CreateWatcher()

Creates a DeviceWatcher for all devices.

public:
 static DeviceWatcher ^ CreateWatcher();
/// [Windows.Foundation.Metadata.Overload("CreateWatcher")]
 static DeviceWatcher CreateWatcher();
[Windows.Foundation.Metadata.Overload("CreateWatcher")]
public static DeviceWatcher CreateWatcher();
function createWatcher()
Public Shared Function CreateWatcher () As DeviceWatcher

Returns

The created DeviceWatcher.

Attributes

Remarks

The DeviceWatcher first performs an initial enumeration of devices, raising an Added event for each device that it finds, and raising an EnumerationCompleted event when the initial enumeration is complete. After the initial enumeration is complete, it raises events when a device is added, deleted, or updated.

See the DeviceWatcher class for an example.

Note

An app must subscribe to all of the added, removed, and updated events to be notified when there are device additions, removals or updates. If an app handles only the added event, it will not receive an update if a device is added to the system after the initial device enumeration completes.

See also

Applies to

CreateWatcher(String)

Creates a DeviceWatcher for devices matching the specified Advanced Query Syntax (AQS) string.

public:
 static DeviceWatcher ^ CreateWatcher(Platform::String ^ aqsFilter);
/// [Windows.Foundation.Metadata.Overload("CreateWatcherAqsFilter")]
 static DeviceWatcher CreateWatcher(winrt::hstring const& aqsFilter);
[Windows.Foundation.Metadata.Overload("CreateWatcherAqsFilter")]
public static DeviceWatcher CreateWatcher(string aqsFilter);
function createWatcher(aqsFilter)
Public Shared Function CreateWatcher (aqsFilter As String) As DeviceWatcher

Parameters

aqsFilter
String

Platform::String

winrt::hstring

An AQS string that filters the DeviceInformation objects to enumerate. Typically this string is retrieved from the GetDeviceSelector method of a class that interacts with devices. For example, GetDeviceSelector retrieves the string for the StorageDevice class.

Returns

The created DeviceWatcher.

Attributes

Remarks

Note

This overload is not available from JavaScript. To create a DeviceWatcher from an AQS string in JavaScript, use the CreateWatcher(String, IIterable_1) overload and pass null as the second parameter.

The DeviceWatcher first performs an initial enumeration of devices, raising an Added event for each device that it finds, and raising an EnumerationCompleted event when the initial enumeration is complete. After the initial enumeration is complete, it raises events when a device is added, deleted, or updated.

Note

An app must subscribe to all of the added, removed, and updated events to be notified when there are device additions, removals or updates. If an app handles only the added event, it will not receive an update if a device is added to the system after the initial device enumeration completes.

See the DeviceWatcher class for an example.

See also

Applies to

CreateWatcher(DeviceClass)

Creates a DeviceWatcher for devices matching the specified DeviceClass.

public:
 static DeviceWatcher ^ CreateWatcher(DeviceClass deviceClass);
/// [Windows.Foundation.Metadata.DefaultOverload]
/// [Windows.Foundation.Metadata.Overload("CreateWatcherDeviceClass")]
 static DeviceWatcher CreateWatcher(DeviceClass const& deviceClass);
[Windows.Foundation.Metadata.DefaultOverload]
[Windows.Foundation.Metadata.Overload("CreateWatcherDeviceClass")]
public static DeviceWatcher CreateWatcher(DeviceClass deviceClass);
function createWatcher(deviceClass)
Public Shared Function CreateWatcher (deviceClass As DeviceClass) As DeviceWatcher

Parameters

deviceClass
DeviceClass

The class of device to enumerate using the DeviceWatcher.

Returns

The created DeviceWatcher.

Attributes

Remarks

The DeviceWatcher first performs an initial enumeration of devices, raising an Added event for each device that it finds, and raising an EnumerationCompleted event when the initial enumeration is complete. After the initial enumeration is complete, it raises events when a device is added, deleted, or updated.

Note

An app must subscribe to all of the added, removed, and updated events to be notified when there are device additions, removals or updates. If an app handles only the added event, it will not receive an update if a device is added to the system after the initial device enumeration completes.

See the DeviceWatcher class for an example.

See also

Applies to

CreateWatcher(String, IIterable<String>)

Creates a DeviceWatcher for devices matching the specified Advanced Query Syntax (AQS) string and the specified collection of properties.

public:
 static DeviceWatcher ^ CreateWatcher(Platform::String ^ aqsFilter, IIterable<Platform::String ^> ^ additionalProperties);
/// [Windows.Foundation.Metadata.Overload("CreateWatcherAqsFilterAndAdditionalProperties")]
 static DeviceWatcher CreateWatcher(winrt::hstring const& aqsFilter, IIterable<winrt::hstring> const& additionalProperties);
[Windows.Foundation.Metadata.Overload("CreateWatcherAqsFilterAndAdditionalProperties")]
public static DeviceWatcher CreateWatcher(string aqsFilter, IEnumerable<string> additionalProperties);
function createWatcher(aqsFilter, additionalProperties)
Public Shared Function CreateWatcher (aqsFilter As String, additionalProperties As IEnumerable(Of String)) As DeviceWatcher

Parameters

aqsFilter
String

Platform::String

winrt::hstring

An AQS string that filters the DeviceInformation objects to enumerate. Typically this string is retrieved from the GetDeviceSelector method of a class that interacts with devices. For example, GetDeviceSelector retrieves the string for the StorageDevice class.

additionalProperties

IIterable<String>

IEnumerable<String>

IIterable<Platform::String>

IIterable<winrt::hstring>

An iterable list of additional properties to include in the Properties property of the DeviceInformation objects in the enumeration results. For more info on what the properties represent, see Device information properties.

Returns

The created DeviceWatcher.

Attributes

Remarks

The DeviceWatcher first performs an initial enumeration of devices, raising an Added event for each device that it finds, and raising an EnumerationCompleted event when the initial enumeration is complete. After the initial enumeration is complete, it raises events when a device is added, deleted, or updated.

Note

An app must subscribe to all of the added, removed, and updated events to be notified when there are device additions, removals or updates. If an app handles only the added event, it will not receive an update if a device is added to the system after the initial device enumeration completes.

See the DeviceWatcher class for an example.

See also

Applies to

CreateWatcher(String, IIterable<String>, DeviceInformationKind)

Creates a DeviceWatcher for devices matching the specified Advanced Query Syntax (AQS) string, the specified collection of properties, and the kind of devices.

public:
 static DeviceWatcher ^ CreateWatcher(Platform::String ^ aqsFilter, IIterable<Platform::String ^> ^ additionalProperties, DeviceInformationKind kind);
/// [Windows.Foundation.Metadata.Overload("CreateWatcherWithKindAqsFilterAndAdditionalProperties")]
 static DeviceWatcher CreateWatcher(winrt::hstring const& aqsFilter, IIterable<winrt::hstring> const& additionalProperties, DeviceInformationKind const& kind);
[Windows.Foundation.Metadata.Overload("CreateWatcherWithKindAqsFilterAndAdditionalProperties")]
public static DeviceWatcher CreateWatcher(string aqsFilter, IEnumerable<string> additionalProperties, DeviceInformationKind kind);
function createWatcher(aqsFilter, additionalProperties, kind)
Public Shared Function CreateWatcher (aqsFilter As String, additionalProperties As IEnumerable(Of String), kind As DeviceInformationKind) As DeviceWatcher

Parameters

aqsFilter
String

Platform::String

winrt::hstring

An AQS string that filters the DeviceInformation objects to enumerate. Typically this string is retrieved from the GetDeviceSelector method of a class that interacts with devices. For example, GetDeviceSelector retrieves the string for the StorageDevice class.

additionalProperties

IIterable<String>

IEnumerable<String>

IIterable<Platform::String>

IIterable<winrt::hstring>

An iterable list of additional properties to include in the Properties property of the DeviceInformation objects in the enumeration results. For more info on what the properties represent, see Device information properties.

kind
DeviceInformationKind

The specific types of devices the DeviceWatcher is interested in.

Returns

The created DeviceWatcher.

Attributes

See also

Applies to

CreateWatcher(String, IIterable<String>, DeviceInformationKind, IDeviceEnumerationSettings)

Creates a DeviceWatcher for devices matching the specified Advanced Query Syntax (AQS) string, the specified collection of properties, the kind of device, and the settings.

public:
 static DeviceWatcher ^ CreateWatcher(Platform::String ^ aqsFilter, IIterable<Platform::String ^> ^ additionalProperties, DeviceInformationKind kind, IDeviceEnumerationSettings ^ settings);
/// [Windows.Foundation.Metadata.Overload("CreateWatcherWithAqsFilterAdditionalPropertiesKindAndSettings")]
 static DeviceWatcher CreateWatcher(winrt::hstring const& aqsFilter, IIterable<winrt::hstring> const& additionalProperties, DeviceInformationKind const& kind, IDeviceEnumerationSettings const& settings);
[Windows.Foundation.Metadata.Overload("CreateWatcherWithAqsFilterAdditionalPropertiesKindAndSettings")]
public static DeviceWatcher CreateWatcher(string aqsFilter, IEnumerable<string> additionalProperties, DeviceInformationKind kind, IDeviceEnumerationSettings settings);
function createWatcher(aqsFilter, additionalProperties, kind, settings)
Public Shared Function CreateWatcher (aqsFilter As String, additionalProperties As IEnumerable(Of String), kind As DeviceInformationKind, settings As IDeviceEnumerationSettings) As DeviceWatcher

Parameters

aqsFilter
String

Platform::String

winrt::hstring

An AQS string that filters the DeviceInformation objects to enumerate. Typically this string is retrieved from the GetDeviceSelector method of a class that interacts with devices. For example, GetDeviceSelector retrieves the string for the StorageDevice class.

additionalProperties

IIterable<String>

IEnumerable<String>

IIterable<Platform::String>

IIterable<winrt::hstring>

An iterable list of additional properties to include in the Properties property of the DeviceInformation objects in the enumeration results. For more info on what the properties represent, see Device information properties.

kind
DeviceInformationKind

The specific types of devices the DeviceWatcher is interested in.

settings
IDeviceEnumerationSettings

Enumeration settings come from a device API's GetDeviceEnumerationSettings method, and contain opaque data. An object implementing this must also implement the IDeviceEnumerationSettings interface.

Returns

The created DeviceWatcher.

Attributes

Windows requirements

Device family
Windows 11, version 24H2 (introduced in 10.0.26100.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v19.0)

Applies to