Bonjour
J'ai une application autonome qui effectue des téléchargements par le web et qui doit donc être capable de se vérifier avant toute chose si elle a accès à internet
pour ça j'ai choisi de la faire pinger yahoo et google (très faible taux de proba que les deux sites soient down en même temps).
Jusque là pas de problème, seulement, si je coupe la connexion réseau j'ai le droit à un joli plantage du programme car la fonction ping "crash" je voulais savoir ou était mon erreur
voici le code
PingExcep1 et 2 sont deux variables strings déclarées et initialisées plus haut à la valeur "0"
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
29
30
31
32 // Pinguer un machine Ping monPing = new Ping(); //l'addresse du ping PingReply Reply = monPing.Send("www.google.com"); //l'exception PingException Pexcep1 = new PingException(PingExcep1); Debug.Write(PingExcep1); // si l'exception est déclanchée on retente un deuxième ping sur yahoo if (PingExcep1 !="0") { Ping monPing1 = new Ping(); PingReply Reply1 = monPing.Send("www.yahoo.com"); PingException Pexcep2 = new PingException(PingExcep2); Debug.Write(PingExcep2); if (PingExcep2 != "0") { Process.Start(new ProcessStartInfo(@SimplOrdiPath)); Application.Exit(); } } // si jamais google est injoignable on test avec yahoo else if (Reply.Status == IPStatus.TimedOut) { Ping monPing2 = new Ping(); PingReply Reply2 = monPing.Send("www.yahoo.com"); if (Reply.Status == IPStatus.TimedOut) { Process.Start(new ProcessStartInfo(@SimplOrdiPath)); Application.Exit(); } }
voila voila
en espérant que vous puissiez m'éclairer
merci d'avance
Rogue 9
Partager