![]() CATEGORIES: BiologyChemistryConstructionCultureEcologyEconomyElectronicsFinanceGeographyHistoryInformaticsLawMathematicsMechanicsMedicineOtherPedagogyPhilosophyPhysicsPolicyPsychologySociologySportTourism |
Processing data from 2 async calls.
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: 1394
|