473,385 Members | 1,973 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,385 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 11244
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.