我有一个正在开发的 Web API Odata 服务。控制器支持异步,但我似乎找不到任何关于如何在从 OData 服务中提取数据时加载 DataGridView 异步的好示例。我确实找到了这个链接,其中有一些内容,但我不知道如何完成其余部分,因为我目前必须将 DataServiceQuery 转换为列表或 DataSource 失败。 http://msdn.microsoft.com/en-us/library/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,所以如果你有任何一个例子,我都会听……