QueryResponse<T>.MoveNextAsync(QueryOptions, CancellationToken) Method

Definition

Advances to the next element of the query results.

public System.Threading.Tasks.Task<bool> MoveNextAsync (Microsoft.Azure.Devices.QueryOptions queryOptions = default, System.Threading.CancellationToken cancellationToken = default);
member this.MoveNextAsync : Microsoft.Azure.Devices.QueryOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<bool>
Public Function MoveNextAsync (Optional queryOptions As QueryOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of Boolean)

Parameters

queryOptions
QueryOptions
cancellationToken
CancellationToken

Returns

True if there was a next item in the query results. False if there were no more items.

Exceptions

If this method made a request to IoT hub to get the next page of items but 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 this method made a request to IoT hub to get the next page of items but 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.

Examples

QueryResponse<Twin> queriedTwins = await iotHubServiceClient.Query.CreateAsync<Twin>("SELECT * FROM devices"); while (await queriedTwins.MoveNextAsync()) { Twin queriedTwin = queriedTwins.Current; Console.WriteLine(queriedTwin); }

Remarks

Like with a more typical implementation of IEnumerator, this function should be called once before checking Current.

This function is async because it may make a service request to fetch the next page of results if the current page of results has been advanced through already. Note that this function will return True even if it is at the end of a particular page of items as long as there is at least one more page to be fetched.

Applies to