Share via


DeviceClient.ReceiveAsync Method

Definition

Overloads

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.

ReceiveAsync(TimeSpan)

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()

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

System.Threading.Tasks.Task<Message>

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

Remarks

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

Applies to

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
System.Threading.CancellationToken

A cancellation token to cancel the operation.

Returns

System.Threading.Tasks.Task<Message>

The receive message or null if there was no message until CancellationToken Expired

Exceptions

System.OperationCanceledException

Thrown when the operation has been canceled.

Remarks

You cannot Reject or Abandon messages over MQTT protocol. For more details, see https://docs.microsoft.com/en-us/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 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(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
System.TimeSpan

Returns

System.Threading.Tasks.Task<Message>

The receive 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/en-us/azure/iot-hub/iot-hub-devguide-messages-c2d#the-cloud-to-device-message-life-cycle.

Applies to