Last post Aug 15, 2019 07:52 PM by JoseSN
Aug 15, 2019 05:39 PM|JoseSN|LINK
How do I call a Async sub or function from the Main?
As Task = ProximityAlerts.RunAsync(f)
Aug 15, 2019 06:17 PM|PatriceSc|LINK
https://blogs.msdn.microsoft.com/mazhou/2017/05/30/c-7-series-part-2-async-main/ is for C# but I guess they have done the same changes for VB ie try Async Sub
Main() which should be supported now. Which VB version do you use ?
Edit: I gave this a try and it doesn't seems to be supported (though I don't find where I can see and check which VB version I'm using). It seems you'll have to use :
Dim result=SearchAlerts("Sample").Result ' For now it doesn't return a result but it seems weird ???
Aug 15, 2019 07:52 PM|JoseSN|LINK
This is what I did and it works.
Finally my problem was related to the .Net framework In 4.5.x the call failed: Dim response As HttpResponseMessage = Await client.GetAsync(URL)
but in 4.6.1 it works fine.
Public Sub SearchAlerts(f As String)
' option 1
Dim result = SearchProximityAlertGetAsyncHttp("3").GetAwaiter().GetResult()
'' option 2
'Dim callTask As Task(Of GResults) = Task.Run(Function() SearchProximityAlertGetAsyncHttp("3"))
'Dim gData As GResults = callTask.Result
Catch ex As Exception
Console.WriteLine("Exception: " & ex.Message)