共用方式為


DeviceClient.SendEventAsync Method

Definition

Overloads

SendEventAsync(Message, CancellationToken)

Sends an event to a hub

SendEventAsync(Message)

Sends an event to a hub

SendEventAsync(Message, CancellationToken)

Sends an event to a hub

public System.Threading.Tasks.Task SendEventAsync (Microsoft.Azure.Devices.Client.Message message, System.Threading.CancellationToken cancellationToken);
member this.SendEventAsync : Microsoft.Azure.Devices.Client.Message * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Function SendEventAsync (message As Message, cancellationToken As CancellationToken) As Task

Parameters

message
Message

The message to send. Should be disposed after sending.

cancellationToken
CancellationToken

A cancellation token to cancel the operation.

Returns

The task to await

Exceptions

Thrown when a required parameter is null.

Thrown if the service does not respond to the request before the expiration of the passed CancellationToken. If a cancellation token is not supplied to the operation call, a cancellation token with an expiration time of 4 minutes is used.

Thrown when the operation has been canceled. The inner exception will be OperationCanceledException.

Thrown if a socket error occurs.

Thrown if an error occurs when performing an operation on a WebSocket connection.

Thrown if an I/O error occurs.

DotNetty.Transport.Channels.ClosedChannelException

Thrown if the MQTT transport layer closes unexpectedly.

Thrown if an error occurs when communicating with IoT hub service. If IsTransient is set to true then it is a transient exception. If IsTransient is set to false then it is a non-transient exception.

Remarks

In case of a transient issue, retrying the operation should work. In case of a non-transient issue, inspect the error details and take steps accordingly. Please note that the list of exceptions is not exhaustive.

Applies to

SendEventAsync(Message)

Sends an event to a hub

public System.Threading.Tasks.Task SendEventAsync (Microsoft.Azure.Devices.Client.Message message);
member this.SendEventAsync : Microsoft.Azure.Devices.Client.Message -> System.Threading.Tasks.Task
Public Function SendEventAsync (message As Message) As Task

Parameters

message
Message

The message to send. Should be disposed after sending.

Returns

The task to await

Exceptions

Thrown when a required parameter is null.

Thrown if the service does not respond to the request within the timeout specified for the operation. The timeout values are largely transport protocol specific. Check the corresponding transport settings to see if they can be configured. The operation timeout for the client can be set using OperationTimeoutInMilliseconds.

Thrown when the operation has been canceled. The inner exception will be OperationCanceledException.

Thrown if a socket error occurs.

Thrown if an error occurs when performing an operation on a WebSocket connection.

Thrown if an I/O error occurs.

DotNetty.Transport.Channels.ClosedChannelException

Thrown if the MQTT transport layer closes unexpectedly.

Thrown if an error occurs when communicating with IoT hub service. If IsTransient is set to true then it is a transient exception. If IsTransient is set to false then it is a non-transient exception.

Remarks

In case of a transient issue, retrying the operation should work. In case of a non-transient issue, inspect the error details and take steps accordingly. Please note that the list of exceptions is not exhaustive.

Applies to