Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

DeviceClient.ReceiveAsync Method

Definition

Namespace:
Microsoft.Azure.Devices.Client
Assemblies:
Microsoft.Azure.Devices.Client.dll, Microsoft.Azure.Devices.Client.PCL.dll
Packages:
Microsoft.Azure.Devices.Client v1.41.2, Microsoft.Azure.Devices.Client.PCL v1.0.16

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Overloads

Name Description
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


Feedback

Was this page helpful?