A
Alhambra Eidos Desarrollo
Hi all mister,
Which is THE BEST WAY IN THE WORLD AROUND for:
1. detect Network
2. detect Internet Connection is working...
which is the best way in the world and good practice recommended by MVPs
Microsoft ?
Thanks in advanced..
code below...but which is the best code ???
NetworkInterface.GetIsNetworkAvailable()
private static int ERROR_SUCCESS = 0;
public static bool IsInternetConnected() {
long dwConnectionFlags = 0;
if (!InternetGetConnectedState(dwConnectionFlags, 0))
return false;
if(InternetAttemptConnect(0) != ERROR_SUCCESS)
return false;
return true;
}
[DllImport("wininet.dll", SetLastError=true)]
public static extern int InternetAttemptConnect(uint res);
[DllImport("wininet.dll", SetLastError=true)]
public static extern bool InternetGetConnectedState(long flags,long
reserved);
Correct translation below.
[DllImport("wininet.dll", SetLastError=true)]
public static extern bool InternetGetConnectedState(out int flags,int
reserved);
I found code in C#, how convert to VB.NET
HttpWebRequest req;
HttpWebResponse resp;
try
{
req = (HttpWebRequest)WebRequest.Create("http://www.google.com");
resp = (HttpWebResponse)req.GetResponse();
if(resp.StatusCode.ToString().Equals("OK"))
{
Console.WriteLine("its connected.");
}
else
{
Console.WriteLine("its not connected.");
}
}
catch(Exception exc)
{
Console.WriteLine("its not connected.");
}
Which is THE BEST WAY IN THE WORLD AROUND for:
1. detect Network
2. detect Internet Connection is working...
which is the best way in the world and good practice recommended by MVPs
Microsoft ?
Thanks in advanced..
code below...but which is the best code ???
NetworkInterface.GetIsNetworkAvailable()
private static int ERROR_SUCCESS = 0;
public static bool IsInternetConnected() {
long dwConnectionFlags = 0;
if (!InternetGetConnectedState(dwConnectionFlags, 0))
return false;
if(InternetAttemptConnect(0) != ERROR_SUCCESS)
return false;
return true;
}
[DllImport("wininet.dll", SetLastError=true)]
public static extern int InternetAttemptConnect(uint res);
[DllImport("wininet.dll", SetLastError=true)]
public static extern bool InternetGetConnectedState(long flags,long
reserved);
Correct translation below.
[DllImport("wininet.dll", SetLastError=true)]
public static extern bool InternetGetConnectedState(out int flags,int
reserved);
I found code in C#, how convert to VB.NET
HttpWebRequest req;
HttpWebResponse resp;
try
{
req = (HttpWebRequest)WebRequest.Create("http://www.google.com");
resp = (HttpWebResponse)req.GetResponse();
if(resp.StatusCode.ToString().Equals("OK"))
{
Console.WriteLine("its connected.");
}
else
{
Console.WriteLine("its not connected.");
}
}
catch(Exception exc)
{
Console.WriteLine("its not connected.");
}