473,387 Members | 1,485 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Detecting a network connection

Hello -

I'm writing an application that will be used on "sometimes connected"
devices (laptops, tablets).

In C#, what is the best way to detect whether a network connection is
present? I'd rather not rely on a network request timing out - the detection
process must be very quick.

Thanks in advance,
Scott


----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 15 '05 #1
3 11245
Check the ispluggedin method of the networkconnection class.

"Scott Leonard" <no**@none.com> wrote in message
news:3f**********@127.0.0.1...
Hello -

I'm writing an application that will be used on "sometimes connected"
devices (laptops, tablets).

In C#, what is the best way to detect whether a network connection is
present? I'd rather not rely on a network request timing out - the detection process must be very quick.

Thanks in advance,
Scott


----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption

=---
Nov 15 '05 #2
Scott Leonard wrote:
Hello -

I'm writing an application that will be used on "sometimes connected"
devices (laptops, tablets).

In C#, what is the best way to detect whether a network connection is
present? I'd rather not rely on a network request timing out - the
detection process must be very quick.


Try System.Windows.Forms.SystemInformation.Network. It is, of course,
true when a network connection is present.
HTH,

Christina Androne

Nov 15 '05 #3
> In C#, what is the best way to detect whether a network
connection is present?


Use WMI, like so:

using System;
using System.Management;
using System.Windows.Forms;

namespace Tests {
public class NetworkProbe {
public static void Main(string []args) {
ObjectQuery objectQuery = new ObjectQuery(
"select * from Win32_NetworkAdapter " +
"where NetConnectionStatus=2"); // 2 means connected

ManagementObjectSearcher searcher =
new ManagementObjectSearcher(objectQuery);

int connectedNetworks = searcher.Get().Count;

if (connectedNetworks > 0) {
Console.WriteLine("There are {0} connected network interfaces",
connectedNetworks);
} else {
Console.WriteLine("There is no network connection present");
}
}
}
}

That should do it,
-JG
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Adam Parkin | last post by:
Hello all, I need to be able to detect if there is an active available Internet connection in my VB6 program. In my program I'm using the Internet Transfer Control to transfer some files by HTTP,...
2
by: Dicky Cheng | last post by:
Hi, I am using .net remoting technology. I set up a .net remoting client and server in IIS. When the client calls the server, the server will run a long duration method (30-60seconds). I have a...
3
by: dotNetDave | last post by:
I just discovered that this: Dim searcher As New Management.ManagementObjectSearcher("SELECT NetConnectionStatus FROM Win32_NetworkAdapter") For Each networkAdapter As...
1
by: TJRobertsJob | last post by:
Was wondering if someone could help. Over the last month I've been developing a small database application, using Access 2000, for use in a friends shop. Everything was going well until about a...
8
by: BobRoyAce | last post by:
I have an ASP.NET application set up on my local hard drive with all pages, dlls, and SQL server on local machine. However, I have discovered that if I reboot my machine without a network cable...
2
by: Brent Burkart | last post by:
I have a utility that I want to only run when a network connection is present. I want to plan for the situation when someone unplugs their laptop from the network and takes it into another...
3
by: Gish Smith | last post by:
How to detect LAN connection in Windows 2000 using VB.Net application ? I want to constantly pool for network connection in my program. How to do that ? Thanks in advance. Gish Smith
5
by: Jonas | last post by:
I want to remove a remote access connection when a user logs out. The connection is a dial up isdn adapter. I can access the adapter via WMI namespace \root\microsoft\homenet, but i donīt find...
0
by: KarthiNatarajan | last post by:
Hi, Is there a way to detect if the network connection is via LAN or 3G or GPRS? I checked all over and not able to find any APIs. I am using .NET 3.5 with C# Thx
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.