다음을 통해 공유


DeviceClient.ReceiveAsync Method

Definition

Overloads

ReceiveAsync(CancellationToken)

Receive a message from the device queue using the cancellation token. After handling a received message, a client should call CompleteAsync(Message, CancellationToken), AbandonAsync(Message, CancellationToken), or RejectAsync(Message, CancellationToken), and then dispose the message.

ReceiveAsync(TimeSpan)

Receive a message from the device queue using a timeout. After handling a received message, a client should call CompleteAsync(Message, CancellationToken), AbandonAsync(Message, CancellationToken), or RejectAsync(Message, CancellationToken), and then dispose the message.

ReceiveAsync()

Receive a message from the device queue using the default timeout. After handling a received message, a client should call CompleteAsync(Message), AbandonAsync(Message), or RejectAsync(Message), and then dispose the message.

ReceiveAsync(CancellationToken)

Receive a message from the device queue using the cancellation token. After handling a received message, a client should call CompleteAsync(Message, CancellationToken), AbandonAsync(Message, CancellationToken), or RejectAsync(Message, CancellationToken), and then dispose the message.

public System.Threading.Tasks.Task<Microsoft.Azure.Devices.Client.Message> ReceiveAsync (System.Threading.CancellationToken cancellationToken);
member this.ReceiveAsync : System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Devices.Client.Message>
Public Function ReceiveAsync (cancellationToken As CancellationToken) As Task(Of Message)

Parameters

cancellationToken
CancellationToken

A cancellation token to cancel the operation.

Returns

The received message or null if there was no message until cancellation token has expired

Exceptions

Thrown when the operation has been canceled.

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

Remarks

You cannot reject or abandon messages over MQTT protocol. For more details, see https://docs.microsoft.com/azure/iot-hub/iot-hub-devguide-messages-c2d#the-cloud-to-device-message-life-cycle.

Applies to

ReceiveAsync(TimeSpan)

Receive a message from the device queue using a timeout. After handling a received message, a client should call CompleteAsync(Message, CancellationToken), AbandonAsync(Message, CancellationToken), or RejectAsync(Message, CancellationToken), and then dispose the message.

public System.Threading.Tasks.Task<Microsoft.Azure.Devices.Client.Message> ReceiveAsync (TimeSpan timeout);
member this.ReceiveAsync : TimeSpan -> System.Threading.Tasks.Task<Microsoft.Azure.Devices.Client.Message>
Public Function ReceiveAsync (timeout As TimeSpan) As Task(Of Message)

Parameters

timeout
TimeSpan

Returns

The received message or null if there was no message until the specified time has elapsed.

Remarks

You cannot reject or abandon messages over MQTT protocol. For more details, see https://docs.microsoft.com/azure/iot-hub/iot-hub-devguide-messages-c2d#the-cloud-to-device-message-life-cycle.

Applies to

ReceiveAsync()

Receive a message from the device queue using the default timeout. After handling a received message, a client should call CompleteAsync(Message), AbandonAsync(Message), or RejectAsync(Message), and then dispose the message.

public System.Threading.Tasks.Task<Microsoft.Azure.Devices.Client.Message> ReceiveAsync ();
member this.ReceiveAsync : unit -> System.Threading.Tasks.Task<Microsoft.Azure.Devices.Client.Message>
Public Function ReceiveAsync () As Task(Of Message)

Returns

The receive message or null if there was no message until the default timeout

Remarks

https://docs.microsoft.com/azure/iot-hub/iot-hub-devguide-messages-c2d#the-cloud-to-device-message-life-cycle.

Applies to