异步加载XML文件
我使用此函数使用Google Maps反向地理编码,并加载一个包含结果的XML:异步加载XML文件,xml,vb.net,asynchronous,Xml,Vb.net,Asynchronous,我使用此函数使用Google Maps反向地理编码,并加载一个包含结果的XML: Private Function ReverseGeocode(ByVal Latitud As Double, ByVal Longitud As Double) As String Dim webClient As New System.Net.WebClient Dim sURL As String = "http://maps.googleapis.com/maps/api/geocode
Private Function ReverseGeocode(ByVal Latitud As Double, ByVal Longitud As Double) As String
Dim webClient As New System.Net.WebClient
Dim sURL As String = "http://maps.googleapis.com/maps/api/geocode/xml?latlng=@lat,@long&sensor=false"
sURL = sURL.Replace("@lat", Latitud)
sURL = sURL.Replace("@long", Longitud)
Dim result As String = webClient.DownloadString(sURL)
Dim xmlDoc As New XmlDocument()
xmlDoc.LoadXml(result)
Dim m_nodelist As XmlNodeList
m_nodelist = xmlDoc.SelectNodes("/GeocodeResponse/result/formatted_address")
ReverseGeocode = m_nodelist(0).InnerText
End Function
我的问题:这可以用异步方法完成吗?可以。与
async
和wait
一起使用异步版本的DownloadString
。您可能需要使用Task.Run
将长时间运行的计算移出UI线程(如果您有)