Click here to Skip to main content
15,890,670 members
Home / Discussions / C#
   

C#

 
AnswerRe: Create Process With User Info Pin
Stefan Troschuetz15-Nov-06 0:03
Stefan Troschuetz15-Nov-06 0:03 
GeneralRe: Create Process With User Info Pin
Ferudun Atakan15-Nov-06 1:14
Ferudun Atakan15-Nov-06 1:14 
GeneralRe: Create Process With User Info Pin
Stefan Troschuetz15-Nov-06 1:26
Stefan Troschuetz15-Nov-06 1:26 
GeneralRe: Create Process With User Info Pin
Ferudun Atakan15-Nov-06 1:59
Ferudun Atakan15-Nov-06 1:59 
GeneralRe: Create Process With User Info Pin
Stefan Troschuetz15-Nov-06 2:16
Stefan Troschuetz15-Nov-06 2:16 
QuestionConnected to the network or not? Pin
mertkan6514-Nov-06 23:17
mertkan6514-Nov-06 23:17 
AnswerRe: Connected to the network or not? Pin
saqib8214-Nov-06 23:51
saqib8214-Nov-06 23:51 
AnswerRe: Connected to the network or not? Pin
Scott Dorman15-Nov-06 8:07
professionalScott Dorman15-Nov-06 8:07 
It really depends on what you mean by "connected to the network". If you are only interested in determining if the network is available (ie, the cable is plugged in and the NIC is getting a signal) you can use the NetworkAvailabilityChangedEventHandler delegate[^].

Using the AddressList property as you show above isn't the most reliable way to check as it may not return the addresses in the order you are expecting, so AddressList[0] isn't guaranteed to be the loopback address. (The better way to test if it is the loopback address is also to do if (IPAd == IPAddress.Loopback) or if (IPAddress.IsLoopback(IPAd)).)

If you need to know if you are connected to the internet, the best options are to try to browse to a website or ping a known address.

Using ping:
C#
bool internetAvailable = false;
 
Ping pinger = new Ping();
PingOptions pingOptions = new PingOptions(1, true);
byte[] pingResults = new byte[2];
 
PingReply pingReply = pinger.Send("www.microsoft.com", 25000, pingResults, pingOptions);
if (pingReply.Status == IPStatus.Success)
{
   internetAvailable = true;
}

Using website:
C#
bool internetAvailable = false;
 
Uri requestUri = new UriBuilder("http", "www.microsoft.com").Uri;
HttpWebRequest connectivityCheck = WebRequest.Create(requestUri) as HttpWebRequest;
 
// A Domain Name System (DNS) query may take up to 15 seconds to return or time out, so
// set the timeout to 25 seconds.
connectivityCheck.Timeout = 25000;
 
HttpWebResponse connectivityResponse = connectivityCheck.GetResponse() as HttpWebResponse;
if (connectivityResponse.StatusCode == HttpStatusCode.OK)
{
   if (!connectivityResponse.IsFromCache)
   {
      internetAvailable = true;
   }
}


-----------------------------
In just two days, tomorrow will be yesterday.

GeneralRe: Connected to the network or not? Pin
mertkan6515-Nov-06 9:13
mertkan6515-Nov-06 9:13 
QuestionDirectoryInfo 1.1 vs 2.0 on UNC paths, strange error Pin
mjma14-Nov-06 23:10
mjma14-Nov-06 23:10 
QuestionFile conversion, need help Pin
Shriya Kapoor14-Nov-06 22:21
Shriya Kapoor14-Nov-06 22:21 
AnswerRe: File conversion, need help Pin
Guffa14-Nov-06 23:07
Guffa14-Nov-06 23:07 
GeneralRe: File conversion, need help Pin
Shriya Kapoor14-Nov-06 23:28
Shriya Kapoor14-Nov-06 23:28 
GeneralRe: File conversion, need help Pin
Shriya Kapoor14-Nov-06 23:30
Shriya Kapoor14-Nov-06 23:30 
QuestionSQLCommand and DataSet Pin
pinebranch14-Nov-06 21:53
pinebranch14-Nov-06 21:53 
AnswerRe: SQLCommand and DataSet Pin
rah_sin15-Nov-06 0:02
professionalrah_sin15-Nov-06 0:02 
QuestionSliding Menu Builder for Windows Application Pin
samtam14-Nov-06 21:23
samtam14-Nov-06 21:23 
QuestionSystem.Media.SoundPlayer Help Pin
AB777114-Nov-06 20:57
AB777114-Nov-06 20:57 
QuestionEventLog in framework 2.0 Pin
ranandbe14-Nov-06 20:48
ranandbe14-Nov-06 20:48 
QuestionNeed Correction Pin
M Riaz Bashir14-Nov-06 20:23
M Riaz Bashir14-Nov-06 20:23 
GeneralRe: Need Correction Pin
Guffa14-Nov-06 20:42
Guffa14-Nov-06 20:42 
GeneralRe: Need Correction Pin
M Riaz Bashir14-Nov-06 20:46
M Riaz Bashir14-Nov-06 20:46 
AnswerRe: Need Correction Pin
Guffa14-Nov-06 23:20
Guffa14-Nov-06 23:20 
GeneralDear Guffa Pin
M Riaz Bashir14-Nov-06 20:48
M Riaz Bashir14-Nov-06 20:48 
GeneralRe: Dear Guffa Pin
Christian Graus14-Nov-06 20:53
protectorChristian Graus14-Nov-06 20:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.