Share via


DataServiceContext.BeginExecute 메서드

정의

데이터 서비스에 특정 URI를 실행하라는 요청을 비동기적으로 보냅니다.

오버로드

BeginExecute<T>(DataServiceQueryContinuation<T>, AsyncCallback, Object)

데이터 서비스에 페이징된 쿼리 결과의 다음 데이터 페이지를 검색하라는 요청을 비동기적으로 보냅니다.

BeginExecute<TElement>(Uri, AsyncCallback, Object)

서비스의 결과를 기다리는 동안 이 호출로 인해 처리가 차단되지 않도록 비동기적으로 요청을 보냅니다.

BeginExecute<T>(DataServiceQueryContinuation<T>, AsyncCallback, Object)

데이터 서비스에 페이징된 쿼리 결과의 다음 데이터 페이지를 검색하라는 요청을 비동기적으로 보냅니다.

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

형식 매개 변수

T

쿼리에서 반환되는 형식입니다.

매개 변수

continuation
DataServiceQueryContinuation<T>

데이터 서비스에서 반환할 다음 데이터 페이지를 나타내는 DataServiceQueryContinuation<T> 개체입니다.

callback
AsyncCallback

결과를 클라이언트 소비에 사용할 수 있는 경우에 호출할 대리자입니다.

state
Object

콜백에 전달된 사용자 정의 상태 개체입니다.

반환

작업 상태를 나타내는 IAsyncResult입니다.

설명

제공된 DataServiceQueryContinuation<T> 개체에는 실행할 때 쿼리 결과에 있는 데이터의 다음 페이지를 반환하는 URI가 포함됩니다.

적용 대상

BeginExecute<TElement>(Uri, AsyncCallback, Object)

서비스의 결과를 기다리는 동안 이 호출로 인해 처리가 차단되지 않도록 비동기적으로 요청을 보냅니다.

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

형식 매개 변수

TElement

쿼리에서 반환되는 형식입니다.

매개 변수

requestUri
Uri

쿼리 요청을 보낼 URI입니다. URI는 유효한 모든 데이터 서비스 URI가 될 수 있으며, $ 쿼리 매개 변수를 포함할 수 있습니다.

callback
AsyncCallback

결과를 클라이언트 소비에 사용할 수 있는 경우에 호출할 대리자입니다.

state
Object

콜백에 전달된 사용자 정의 상태 개체입니다.

반환

비동기 작업의 상태를 추적하는 데 사용되는 개체입니다.

예제

다음 예제에서는 메서드를 호출하여 비동기 쿼리를 BeginExecute 실행하여 쿼리를 시작하는 방법을 보여줍니다. 인라인 대리자는 메서드를 EndExecute 호출하여 쿼리 결과를 표시합니다. 이 예제에서는 WCF Data Services 완료할 때 만들어지는 Northwind 데이터 서비스를 기반으로 서비스 참조 추가 도구에서 생성된 를 사용합니다DataServiceContext.

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

설명

반환된 IAsyncResult 개체는 비동기 작업이 완료된 시점을 확인하는 데 사용됩니다. 자세한 내용은 비동기 작업합니다.

메서드 BeginExecute 는 와 Execute동일한 의미 체계를 사용하지만 이 메서드는 서비스의 결과를 기다리는 동안 이 호출이 처리를 차단하지 않도록 요청을 비동기적으로 보냅니다. 제공된 콜백은 표준 시작-끝 비동기 패턴에 따라 쿼리 결과가 검색되면 호출됩니다.

추가 정보

적용 대상