DataServiceContext.BeginExecute Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
De forma assíncrona, envia um pedido ao serviço de dados para executar um URI específico.
Sobrecargas
| Name | Description |
|---|---|
| BeginExecute<T>(DataServiceQueryContinuation<T>, AsyncCallback, Object) |
De forma assíncrona, envia um pedido ao serviço de dados para recuperar a página seguinte de dados num resultado de consulta paginada. |
| BeginExecute<TElement>(Uri, AsyncCallback, Object) |
Envia o pedido de forma assíncrona para que esta chamada não bloqueie o processamento enquanto aguarda os resultados do serviço. |
BeginExecute<T>(DataServiceQueryContinuation<T>, AsyncCallback, Object)
De forma assíncrona, envia um pedido ao serviço de dados para recuperar a página seguinte de dados num resultado de consulta paginada.
public:
generic <typename T>
IAsyncResult ^ BeginExecute(System::Data::Services::Client::DataServiceQueryContinuation<T> ^ continuation, AsyncCallback ^ callback, System::Object ^ state);
public IAsyncResult BeginExecute<T>(System.Data.Services.Client.DataServiceQueryContinuation<T> continuation, AsyncCallback callback, object state);
member this.BeginExecute : System.Data.Services.Client.DataServiceQueryContinuation<'T> * AsyncCallback * obj -> IAsyncResult
Public Function BeginExecute(Of T) (continuation As DataServiceQueryContinuation(Of T), callback As AsyncCallback, state As Object) As IAsyncResult
Parâmetros de Tipo Genérico
- T
O tipo devolvido pela consulta.
Parâmetros
- continuation
- DataServiceQueryContinuation<T>
Um DataServiceQueryContinuation<T> objeto que representa a próxima página de dados a devolver do serviço de dados.
- callback
- AsyncCallback
Delegar para invocar quando os resultados estiverem disponíveis para consumo pelo cliente.
- state
- Object
O objeto de estado definido pelo utilizador é passado para o callback.
Devoluções
E IAsyncResult isso representa o estado da operação.
Observações
O objeto fornecido DataServiceQueryContinuation<T> contém o URI que, quando executado, devolve a página seguinte de dados no resultado da consulta.
Aplica-se a
BeginExecute<TElement>(Uri, AsyncCallback, Object)
Envia o pedido de forma assíncrona para que esta chamada não bloqueie o processamento enquanto aguarda os resultados do serviço.
public:
generic <typename TElement>
IAsyncResult ^ BeginExecute(Uri ^ requestUri, AsyncCallback ^ callback, System::Object ^ state);
public IAsyncResult BeginExecute<TElement>(Uri requestUri, AsyncCallback callback, object state);
member this.BeginExecute : Uri * AsyncCallback * obj -> IAsyncResult
Public Function BeginExecute(Of TElement) (requestUri As Uri, callback As AsyncCallback, state As Object) As IAsyncResult
Parâmetros de Tipo Genérico
- TElement
O tipo devolvido pela consulta.
Parâmetros
- requestUri
- Uri
O URI para onde o pedido de consulta será enviado. O URI pode ser qualquer URI válido de serviço de dados; pode conter $ parâmetros de consulta.
- callback
- AsyncCallback
Delegar para invocar quando os resultados estiverem disponíveis para consumo pelo cliente.
- state
- Object
O objeto de estado definido pelo utilizador é passado para o callback.
Devoluções
Um objeto usado para acompanhar o estado da operação assíncrona.
Exemplos
O exemplo seguinte mostra como executar uma consulta assíncrona chamando o BeginExecute método para iniciar a consulta. O delegado inline chama o EndExecute método para mostrar os resultados da consulta. Este exemplo utiliza a DataServiceContext ferramenta gerada pela Adicionar Referência de Serviço baseada no serviço de dados Northwind, que é criada quando se completa o WCF Data Services .
public static void BeginExecuteCustomersQuery()
{
// Create the DataServiceContext using the service URI.
NorthwindEntities context = new NorthwindEntities(svcUri);
// Define the query to execute asynchronously that returns
// all customers with their respective orders.
DataServiceQuery<Customer> query = (DataServiceQuery<Customer>)(from cust in context.Customers.Expand("Orders")
where cust.CustomerID == "ALFKI"
select cust);
try
{
// Begin query execution, supplying a method to handle the response
// and the original query object to maintain state in the callback.
query.BeginExecute(OnCustomersQueryComplete, query);
}
catch (DataServiceQueryException ex)
{
throw new ApplicationException(
"An error occurred during query execution.", ex);
}
}
// Handle the query callback.
private static void OnCustomersQueryComplete(IAsyncResult result)
{
// Get the original query from the result.
DataServiceQuery<Customer> query =
result as DataServiceQuery<Customer>;
foreach (Customer customer in query.EndExecute(result))
{
Console.WriteLine("Customer Name: {0}", customer.CompanyName);
foreach (Order order in customer.Orders)
{
Console.WriteLine("Order #: {0} - Freight $: {1}",
order.OrderID, order.Freight);
}
}
}
Public Shared Sub BeginExecuteCustomersQuery()
' Create the DataServiceContext using the service URI.
Dim context = New NorthwindEntities(svcUri)
' Define the delegate to callback into the process
Dim callback As AsyncCallback = AddressOf OnCustomersQueryComplete
' Define the query to execute asynchronously that returns
' all customers with their respective orders.
Dim query As DataServiceQuery(Of Customer) =
context.Customers.Expand("Orders")
Try
' Begin query execution, supplying a method to handle the response
' and the original query object to maintain state in the callback.
query.BeginExecute(callback, query)
Catch ex As DataServiceQueryException
Throw New ApplicationException(
"An error occurred during query execution.", ex)
End Try
End Sub
' Handle the query callback.
Private Shared Sub OnCustomersQueryComplete(ByVal result As IAsyncResult)
' Get the original query from the result.
Dim query As DataServiceQuery(Of Customer) =
CType(result.AsyncState, DataServiceQuery(Of Customer))
' Complete the query execution.
For Each customer As Customer In query.EndExecute(result)
Console.WriteLine("Customer Name: {0}", customer.CompanyName)
For Each order As Order In customer.Orders
Console.WriteLine("Order #: {0} - Freight $: {1}",
order.OrderID, order.Freight)
Next
Next
End Sub
Observações
O objeto devolvido IAsyncResult é usado para determinar quando a operação assíncrona foi concluída. Para mais informações, consulte Operações Assíncronas.
O método BeginExecute utiliza a mesma semântica que Execute, no entanto, este método envia o pedido de forma assíncrona para que esta chamada não bloqueie o processamento enquanto se espera pelos resultados do serviço. De acordo com o padrão assíncrono início-fim, o callback fornecido é invocado quando os resultados da consulta são recuperados.