hi im amir
im a noob in c# and need some help
i coding a net based app and i need to ping to website if ok run app else close app
the bug is when im online show ok message but when im offline app runnig and show error for debugging.
please help
thankyou
here is my code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
////////////////////////////////////
using System.Net.NetworkInformation;
////////////////////////////////////
namespace CheckInternetConnection
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Ping ping = new Ping();
PingReply pingStatus = ping.Send("google.com");
if (pingStatus.Status == IPStatus.Unknown)
{
Application.Exit();
}
else
{
ImgStatus.Visible = true;
lblStatus.Visible = true;
ImgStatus.BackgroundImage = CheckInternetConnection.Properties.Resources.Actions_dialog_ok_apply_icon;
lblStatus.Text = "OK network active";
lblStatus.ForeColor = Color.FromArgb(0, 192, 0);
}
}
}
}