문제

나는 웹 API Odata 서비스가 일하고 있습니다.컨트롤러는 비동기를 지원하지만 OData 서비스에서 데이터를 가져 오는 동안 DataGridView 비동기를로드하는 방법에 대해 좋은 예를 찾을 수 없습니다.나는이 링크를 찾았습니다. 현재 DataServiceQuery를 목록으로 변환하거나 DataSource가 실패하기 때문에 나머지를 완성하는 방법을 모르겠습니다. http://msdn.microsoft.com/ko미국 / 라이브러리 / DD756367 (v= vs.110) .aspx
내 코드는 이와 같은 것입니다.

Private Sub getDataButton_Click(sender As Object, e As EventArgs) Handles getDataButton.Click
    ' Define the delegate to callback into the process 
    Dim callback As AsyncCallback = AddressOf OnLogsQueryComplete

    ' Define the query to execute asynchronously that returns  
    ' all customers with their respective orders. 
    Dim query As DataServiceQuery(Of LogServiceReference.Log) = (From log In context.Logs
                                                                   Select log)

    ' Begin query execution, supplying a method to handle the response 
    ' and the original query object to maintain state in the callback.
    DataGridView1.DataSource = query.BeginExecute(callback, query)
End Sub

Private Function OnLogsQueryComplete(ByVal result As IAsyncResult) As List(Of LogServiceReference.Log)
    ' Get the original query from the result. 
    Dim query As DataServiceQuery(Of LogServiceReference.Log) = _
        CType(result.AsyncState, DataServiceQuery(Of LogServiceReference.Log))

    Return query.EndExecute(result).ToList()
End Function
.

C # 또는 VB를 읽을 수 있습니다. 그래서 모든 귀에있는 예제가 있다면 ...

도움이 되었습니까?

해결책

이는 진정으로 그리드 로열로 바이 - 행 비동기를 채우지 않지만 전체 데이터 소스 비동기 전체를 채우고 있습니다.내가 사용한 코드는 다음과 같습니다.

Private gridRows As List(Of LogServiceReference.Log) = New List(Of LogServiceReference.Log)()
Private Delegate Sub UpdateUI()
Private oUpdateUI As UpdateUI

Private Sub getDataButton_Click(sender As Object, e As EventArgs) Handles getDataButton.Click
    Try
        gridRows.Clear()
        DataGridView1.DataSource = Nothing

        oUpdateUI = New UpdateUI(AddressOf DoUpdateUI)

        ' Define the delegate to callback into the process 
        Dim callback As AsyncCallback = AddressOf OnLogsQueryComplete

        ' Define the query to execute asynchronously that returns  
        ' all customers with their respective orders. 
        Dim query As DataServiceQuery(Of LogServiceReference.Log) = (From log In context.Logs
                                                                       Select log)

        ' 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 Exception

    End Try
End Sub

Private Sub DoUpdateUI()
    DataGridView1.DataSource = gridRows
End Sub

Private Sub OnLogsQueryComplete(ByVal result As IAsyncResult)
    ' Get the original query from the result. 
    Dim query As DataServiceQuery(Of LogServiceReference.Log) = _
        CType(result.AsyncState, DataServiceQuery(Of LogServiceReference.Log))

    ' Complete the query execution. 
    For Each log As LogServiceReference.Log In query.EndExecute(result)
        gridRows.Add(log)
    Next

    Invoke(oUpdateUI)
End Sub
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top