Servicios de datos Client Async Cargar DataGridView
Pregunta
Tengo un servicio web de API ODATA en el que estoy trabajando.El controlador admite ASYNC, pero parece que no puedo encontrar buenos ejemplos sobre cómo cargar un DataGridView ASYNC mientras tire de los datos del servicio ODATA.Encontré este enlace que me tiene algo de lo que allí, pero no sé cómo terminar el resto porque actualmente tengo que convertir el DataServicSquery en una lista o la fuente de datos falla. http://msdn.microsoft.com/en-US / Library / DD756367 (v= vs.110) .aspx
Mi código es algo así.
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
Puedo leer / codificar C # o VB, por lo que si tiene ejemplos de yo soy todos los oídos ...
Solución
Si bien esto no está realmente poblando una cuadrícula de fila por fila ASYNC, está rellenando todo el DataSource Async.Aquí está el código que utilizo.
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