Processing data from 2 async calls. Perhaps your problem is when to process the data from the 2 responses. This is what I do: Define a call counter to count the responses, clear it, the send the 2 async requests:
Code:
Private oMarketPrices As UnpackMarketPricesCompressed
Private oTradedVolume As UnpackMarketTradedVolumeCompressed
Private CallCount As Integer
Private Sub GetMarketData() 'Sub to send the requests
CallCount = 0 'Clear the call count
Call getMarketPricesCompressedAsync (as per step 14)
Call getMarketTradedVolumeCompressedAsync (as per step 24)
End Sub
The API now sends back the 2 responses. Problem is we don’t know which one comes back first, so we count them in the event handlers. When both responses have been received CallCount = 2, so now we call a sub to process the 2 unpacked data objects.
Code:
Private Sub BetfairUK_getMarketPricesCompressedCompleted(ByVal sender As Object, ByVal e As BFUK.getMarketPricesCompressedCompletedEventArgs) Handles BetfairUK.getMarketPricesCompressedCompleted
.........
(Code similar to Step 14)
.........
If .errorCode = BFUK.GetMarketPricesErrorEnum.OK Then
oMarketPrices = New UnpackMarketPricesCompressed(.marketPrices) 'Unpack the market prices data
CallCount += 1 'Count this response
If CallCount = 2 Then BuildDataTable() 'Process responses when both received
End If
.........
.........
End Sub
Private Sub BetfairUK_getMarketTradedVolumeCompressedCompleted(ByVal sender As Object, ByVal e As BFUK.getMarketTradedVolumeCompressedCompletedEventArgs) Handles BetfairUK.getMarketTradedVolumeCompressedCompleted
........
(Code similar to Step 24)
........
If .errorCode = BFUK.GetMarketTradedVolumeCompressedErrorEnum.OK Then
oTradedVolume = New UnpackMarketTradedVolumeCompressed(.tradedVolume) 'Unpack the traded volume data
CallCount += 1 'Count this response
If CallCount = 2 Then BuildDataTable() 'Process responses when both received
End If
.........
.........
End Sub
Private Sub BuildDataTable()
Builds a data table from data contained in oMarketPrices and oTradedVolume objects
End Sub
Sub BuildDataTable is only called once, from the event handler which handles the second response (whichever that is). This ensures that both responses have arrived before output processing commences.
Date: 2014-12-21; view: 1198
|