Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / August 2006

Tip: Looking for answers? Try searching our database.

Check if internet is up

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Janiek Buysrogge - 30 Aug 2006 14:15 GMT
Hi,

I'm using the following code to check if there is a connection to the
internet:

       #region
       //Creating the extern function...
       [DllImport("wininet.dll")]
       private extern static bool InternetGetConnectedState(out int
Description, int ReservedValue);
       #endregion

       public Form1()
       {
           InitializeComponent();
       }

       private void button1_Click(object sender, EventArgs e)
       {
           int Desc;
           bool res = InternetGetConnectedState(out Desc, 0);

           Console.WriteLine("Inet is up: " + res);
       }

The strange thing is that it always returns false, even as I am
writing this message and while browsing the web.

I am connected to the internet via LAN in my company. Maybe this
function is more aimed at modem users ?

Is there any clarification for this ?

Thanks,

JB
Janiek Buysrogge - 30 Aug 2006 14:31 GMT
Hello,

Now I'm using the following code, seems to work:

Solution:

       #region
       [DllImport("wininet.dll")]
       private extern static bool InternetCheckConnection(string
Description, int Flags, int ReservedValue);
       #endregion

       public Form1()
       {
           InitializeComponent();
       }

       private void button2_Click(object sender, EventArgs e)
       {
           int Desc;
           bool res = InternetCheckConnection("http://www.google.be",
1, 0);

           Console.WriteLine("Inet is up: " + res);
       }

JB

>Hi,
>
[quoted text clipped - 32 lines]
>
>JB

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.