Gestion de ressource pour une fontion
Bonsoir, en rapport avec mon projet de localiser une ville, j'ai fait une fonction servant a trouver l'adresse ip publique (WAN), celle ci marche parfaitement seulement voila, lorsque j'appelle cette fonction la mémoire du processus monte enormement et ne redescend pas apres, alors que cette fonction ne retourne qu'un string.
Et puisque je ne suis pas un expert en libération de ressources je vous sollicite pour m'apprendre a optimiser cette fonction.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| Function IPwan()
Dim WebBrowser1 As New WebBrowser
Dim IP As String
WebBrowser1.ScriptErrorsSuppressed = True
Try
a:
WebBrowser1.Navigate("http://whatsmyip.net/")
Do While WebBrowser1.ReadyState <> WebBrowserReadyState.Complete
Application.DoEvents()
Loop
Dim Source As String = WebBrowser1.DocumentText
IP = Source.Substring(Source.IndexOf(">IP</acronym> Address is <input type=") + 51)
IP = IP.Substring(0, IP.IndexOf(" /></h1>") - 1)
Catch
Try
WebBrowser1.Navigate("http://www.my-ip-address.net/")
Do While WebBrowser1.ReadyState <> WebBrowserReadyState.Complete
Application.DoEvents()
Loop
Dim Source As String = WebBrowser1.DocumentText
IP = Source.Substring(Source.IndexOf("Your IP Address is<br/><span>") + 29)
IP = IP.Substring(0, IP.IndexOf("</span"))
Catch
GoTo a
End Try
End Try
Return IP
End Function |
Je vous remercie, bonne soirée :D