Advertisement
Guest User

Main.cs

a guest
Nov 4th, 2014
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.64 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. using System.Net;
  16. using System.Net.NetworkInformation;
  17.  
  18. namespace WpfApplication1
  19. {
  20.  
  21.  
  22.     /// <summary>
  23.     /// Interaction logic for MainWindow.xaml
  24.     /// </summary>
  25.     public partial class MainWindow : Window
  26.     {
  27.         public void DoThePing() {
  28.             try
  29.             {
  30.                 Ping pingSender = new Ping();
  31.                 PingReply MainServer = pingSender.Send("www.pattersoncode.ca");
  32.                 PingReply BackupServer = pingSender.Send("82.145.60.186");
  33.                 PingReply CDN = pingSender.Send("d11ghhslktyes5.cloudfront.net");
  34.  
  35.                 if (MainServer.Status == IPStatus.Success)
  36.                 {
  37.                     mainlabel.Content = MainServer.RoundtripTime + " ms";
  38.                     mainlabel.Foreground = Brushes.DarkGreen;
  39.                 }
  40.                 else
  41.                 {
  42.                     mainlabel.Content = "Failure";
  43.                     mainlabel.Foreground = Brushes.Red;
  44.  
  45.                 }
  46.  
  47.                 if (CDN.Status == IPStatus.Success)
  48.                 {
  49.                     cdnlabel.Content = CDN.RoundtripTime + " ms";
  50.                     cdnlabel.Foreground = Brushes.DarkGreen;
  51.                 }
  52.                 else
  53.                 {
  54.                     cdnlabel.Content = "Failure";
  55.                     cdnlabel.Foreground = Brushes.Red;
  56.  
  57.                 }
  58.  
  59.                 if (BackupServer.Status == IPStatus.Success)
  60.                 {
  61.                     backuplabel.Content = BackupServer.RoundtripTime + " ms";
  62.                     backuplabel.Foreground = Brushes.DarkGreen;
  63.  
  64.                 }
  65.                 else
  66.                 {
  67.                     backuplabel.Content = "Failure";
  68.                     backuplabel.Foreground = Brushes.Red;
  69.  
  70.                 }
  71.             }
  72.             catch (Exception ex)
  73.             {
  74.                 MessageBox.Show(ex.Message, "Exception");
  75.             }
  76.         }
  77.    
  78.  
  79.         public MainWindow()
  80.         {
  81.             InitializeComponent();
  82.         }
  83.  
  84.         private void Button_Click(object sender, RoutedEventArgs e)
  85.         {
  86.             DoThePing();
  87.         }
  88.  
  89.         private void Grid_Loaded(object sender, RoutedEventArgs e)
  90.         {
  91.             DoThePing();
  92.         }
  93.     }
  94.  
  95.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement