I would use System.Net.NetworkInformation.Ping and ping Google.co.uk. then determining whether there is a time out or not check this out seems to solve your question. However this will only tell you if the port is active, not whether you have connection, so may be a crude fix follow this link
How do you check if a website is online in C#?
Edit:
another option is by the following:
Begin by creating a separate method as per below, within your winform
project
public static bool CheckNetwork()
{
if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
{
//Do your stuffs when network available
return true;
}
else
{
//When network not available,
return false;
}
}
Then within your formload
Event handler
have the following. This action will then be performed when the form is loaded. You can then have what other functionality you want to perform based of the separate method.
private void Form1_Load(object sender, EventArgs e)
{
if (!CheckNetwork())
{
MessageBox.Show("No connection available");
this.Close();
}
else
{
MessageBox.Show("Network connection available");
}
}