0

제가 작업하고있는 웹 API Odata 서비스가 있습니다. 컨트롤러가 비동기를 지원하지만 OData 서비스에서 데이터를 가져 오는 동안 DataGridView 비동기를로드하는 방법에 대한 좋은 예제를 찾지 못하는 것 같습니다. 나는 거기에 어떤 것을 가지고있는이 링크를 찾았지만 현재 DataServiceQuery를 목록으로 변환해야하거나 DataSource가 실패하기 때문에 나머지를 완료하는 방법을 모른다. http://msdn.microsoft.com/en-us/library/dd756367(v=vs.110).aspx
내 코드는 다음과 같습니다. 당신은 내가 모든 귀를 오전 중 하나의 예를 그래서 만약이 진정한 그리드 행 단위 비동기를 채우는 것은 아니지만
데이터 서비스 클라이언트 비동기로드 DataGridView

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 

나는 ...,

답변

0

을/코드 중 하나를 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