I have the following code
Public Async Function GetApiVersionAsync() As Task(Of Object)
Debug.Print(0)
Dim response As HttpResponseMessage = Await httpClient.GetAsync(BASE_URI & "/api/version")
Debug.Print(1)
Dim responseContent As String = Await response.Content.ReadAsStringAsync()
Debug.Print("Result2:" & responseContent)
Return responseContent
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim MyNfonService As New NfonService
Dim s As String
Debug.Print("a")
s = MyNfonService.GetApiVersionAsync().ToString
Debug.Print("Result1:" & s)
Debug.Print("b")
End Sub
I would expect the debug outputs to be in the following order
a
0
1
Result2: (some reasonable response text)
Result1: (same response text)
b
I AM getting
a
0
Result1: (nothing)
b
1
Result2: (some reasonable response text)
Shouldn’t Dim response As HttpResponseMessage = Await httpClient.GetAsync(BASE_URI & "/api/version")
wait for the httpClient.GetAsync to return a response before continueing? What am I missing?