Aracılığıyla paylaş


DataServiceContext.BeginExecute Yöntem

Tanım

Belirli bir URI'yi yürütmek için veri hizmetine zaman uyumsuz olarak bir istek gönderir.

Aşırı Yüklemeler

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

Zaman uyumsuz olarak veri hizmetine, sayfalanmış sorgu sonucundaki bir sonraki veri sayfasını alma isteği gönderir.

BeginExecute<TElement>(Uri, AsyncCallback, Object)

Bu çağrının hizmetten sonuçları beklerken işlemeyi engellememesi için isteği zaman uyumsuz olarak gönderir.

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

Zaman uyumsuz olarak veri hizmetine, sayfalanmış sorgu sonucundaki bir sonraki veri sayfasını alma isteği gönderir.

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ür Parametreleri

T

Sorgu tarafından döndürülen tür.

Parametreler

continuation
DataServiceQueryContinuation<T>

Veri DataServiceQueryContinuation<T> hizmetinden döndürülecek bir sonraki veri sayfasını temsil eden nesne.

callback
AsyncCallback

İstemci tüketimi için sonuçlar kullanılabilir olduğunda çağrılacak temsilci.

state
Object

Geri çağırmaya geçirilen kullanıcı tanımlı durum nesnesi.

Döndürülenler

IAsyncResult İşlemin durumunu temsil eden bir.

Açıklamalar

Sağlanan DataServiceQueryContinuation<T> nesne, yürütüldüğünde sorgu sonucunda bir sonraki veri sayfasını döndüren URI'yi içerir.

Şunlara uygulanır

BeginExecute<TElement>(Uri, AsyncCallback, Object)

Bu çağrının hizmetten sonuçları beklerken işlemeyi engellememesi için isteği zaman uyumsuz olarak gönderir.

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

Tür Parametreleri

TElement

Sorgu tarafından döndürülen tür.

Parametreler

requestUri
Uri

Sorgu isteğinin gönderileceği URI. URI herhangi bir geçerli veri hizmeti URI'si olabilir; sorgu parametreleri içerebilir $ .

callback
AsyncCallback

İstemci tüketimi için sonuçlar kullanılabilir olduğunda çağrılacak temsilci.

state
Object

Geri çağırmaya geçirilen kullanıcı tanımlı durum nesnesi.

Döndürülenler

Zaman uyumsuz işlemin durumunu izlemek için kullanılan nesne.

Örnekler

Aşağıdaki örnekte, sorguyu başlatmak için yöntemini çağırarak zaman uyumsuz bir sorgunun BeginExecute nasıl yürütüldiği gösterilmektedir. Satır içi temsilci sorgu sonuçlarını görüntülemek için yöntemini çağırır EndExecute . Bu örnekteDataServiceContext, WCF Veri Hizmetleri tamamladığınızda oluşturulan Northwind veri hizmetini temel alan Hizmet Başvurusu Ekleme aracı tarafından oluşturulan kullanılır.

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

Açıklamalar

Döndürülen IAsyncResult nesne, zaman uyumsuz işlemin ne zaman tamamlandığını belirlemek için kullanılır. Daha fazla bilgi için bkz. Zaman Uyumsuz İşlemler.

yöntemi BeginExecute ile aynı semantiği Executekullanır, ancak bu yöntem isteği zaman uyumsuz olarak gönderir, böylece bu çağrı hizmetten sonuçları beklerken işlemeyi engellemez. Standart başlangıç-bitiş zaman uyumsuz desenine göre, sorgu sonuçları alındığında sağlanan geri çağırma çağrılır.

Ayrıca bkz.

Şunlara uygulanır