Bagikan melalui


DevicesClient.SetAsync Method

Definition

Overloads

SetAsync(Device, Boolean, CancellationToken)

Replace a device identity's state with the provided device identity's state.

SetAsync(IEnumerable<Device>, Boolean, CancellationToken)

Update up to 100 device identities in your IoT hub's registry in bulk.

SetAsync(Device, Boolean, CancellationToken)

Replace a device identity's state with the provided device identity's state.

public virtual System.Threading.Tasks.Task<Microsoft.Azure.Devices.Device> SetAsync (Microsoft.Azure.Devices.Device device, bool onlyIfUnchanged = false, System.Threading.CancellationToken cancellationToken = default);
abstract member SetAsync : Microsoft.Azure.Devices.Device * bool * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Devices.Device>
override this.SetAsync : Microsoft.Azure.Devices.Device * bool * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Devices.Device>
Public Overridable Function SetAsync (device As Device, Optional onlyIfUnchanged As Boolean = false, Optional cancellationToken As CancellationToken = Nothing) As Task(Of Device)

Parameters

device
Device

The device identity's new state.

onlyIfUnchanged
Boolean

If false, this update operation will be performed even if the provided device identity has an out of date ETag. If true, the operation will throw a IotHubServiceException with PreconditionFailed if the provided device identity has an out of date ETag. An up-to-date ETag can be retrieved using GetAsync(String, CancellationToken).

cancellationToken
CancellationToken

The token which allows the operation to be canceled.

Returns

The newly updated device identity including its new ETag.

Exceptions

When the provided device is null.

If IoT hub responded to the request with a non-successful status code. For example, if the provided request was throttled, IotHubServiceException with ThrottlingException is thrown. For a complete list of possible error cases, see IotHubServiceErrorCode.

If the HTTP request fails due to an underlying issue such as network connectivity, DNS failure, or server certificate validation.

If the provided cancellation token has requested cancellation.

Applies to

SetAsync(IEnumerable<Device>, Boolean, CancellationToken)

Update up to 100 device identities in your IoT hub's registry in bulk.

public virtual System.Threading.Tasks.Task<Microsoft.Azure.Devices.BulkRegistryOperationResult> SetAsync (System.Collections.Generic.IEnumerable<Microsoft.Azure.Devices.Device> devices, bool onlyIfUnchanged = false, System.Threading.CancellationToken cancellationToken = default);
abstract member SetAsync : seq<Microsoft.Azure.Devices.Device> * bool * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Devices.BulkRegistryOperationResult>
override this.SetAsync : seq<Microsoft.Azure.Devices.Device> * bool * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Devices.BulkRegistryOperationResult>
Public Overridable Function SetAsync (devices As IEnumerable(Of Device), Optional onlyIfUnchanged As Boolean = false, Optional cancellationToken As CancellationToken = Nothing) As Task(Of BulkRegistryOperationResult)

Parameters

devices
IEnumerable<Device>

The device identities to update to your IoT hub's registry. May not exceed 100 devices.

onlyIfUnchanged
Boolean

If false, this update operation will be performed even if the provided device identity has an out of date ETag. If true, the operation will throw a IotHubServiceException with PreconditionFailed if the provided device identity has an out of date ETag. An up-to-date ETag can be retrieved using GetAsync(String, CancellationToken).

cancellationToken
CancellationToken

The token which allows the operation to be canceled.

Returns

The result of the bulk operation.

Exceptions

When the provided device collection is null.

When the provided device collection is empty.

If IoT hub responded to the request with a non-successful status code. For example, if the provided request was throttled, IotHubServiceException with ThrottlingException is thrown. For a complete list of possible error cases, see IotHubServiceErrorCode.

If the HTTP request fails due to an underlying issue such as network connectivity, DNS failure, or server certificate validation.

If the provided cancellation token has requested cancellation.

Applies to