.NETGURU
internet connection
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.windowsforms.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

Konrad
Hi

I'am checking in separate thread does the connection with
internet is estabilished. But program freezes
for 2-3 secs. How to do that user
doesn't feel this checking?

thanks
Konrad

Reply to this message...
 
    
Herfried K. Wagner [MVP] (VIP)
* "Konrad" <Click here to reveal e-mail address> scripsit:
[Original message clipped]

How do you check if the connection is established?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Reply to this message...
 
    
Konrad
I found this method and it is quick

//Creating the extern function...

[DllImport("wininet.dll")]

private extern static bool InternetGetConnectedState(

out int Description, int ReservedValue ) ;

public static bool IsConnectedToInternet( )

{

int Desc ;

return InternetGetConnectedState( out Desc, 0 ) ;

}

and previous method

public static bool IsInternetConnected(string url)

{

bool FoundUrl = true;

try

{

WebRequest req;

WebResponse result;

Stream ReceiveStream;

Encoding encode;

StreamReader sr;

req = WebRequest.Create(url);

req.Timeout = 5000;

result = req.GetResponse();

ReceiveStream = result.GetResponseStream();

encode = System.Text.Encoding.GetEncoding("utf-8");

sr = new StreamReader(ReceiveStream, encode);

}

catch(System.Exception e)

{

FoundUrl = false;

}

return FoundUrl;

}

Thanks

Konrad

"Herfried K. Wagner [MVP]" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
MuZZY
Konrad wrote:

[Original message clipped]

Hi Konrad,

Well, i've seen in a few articles that using any windows api functions
to test internet connection isn't reliable anyway - at the most it will
say that you are connected, but it can't check either it's just a LAN
connection, or internet.

What i would do is try to establish a conection with a well nown web
site, say yahoo or google using System.Net.HttpWebRequest class.
I am not sure if it's a synchronous or asynchronous socket connection,
but anyway you can launch it in a separate thread.
I remember myself doing that back in Delphi couple years ago, and it
worked fine!

Andrey
Reply to this message...
 
 
System.Exception
System.IO.StreamReader
System.Net.HttpWebRequest
System.Net.WebRequest
System.Net.WebResponse
System.Text.Encoding




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification