Network in C#: how to detect that I have a break connection
-
Hi, I would like to know in C# : how to detect that I have a break or connection with the network? Best Regards youssef
As we've discussed in this board before, you should P/Invoke any one of various native functions like
InternetCheckConnection
:public bool Connected
{
get { return InternetCheckConnection("http://www.codeproject.com", 0, 0); }
}
[DllImport("wininet.dll", CharSet=CharSet.Auto, SetLastError=true)]
static extern bool InternetCheckConnection(string url, int flags, int reserved);You can also use this and similar functions defined in the WinInet library to force connections. Look-up that function in the MSDN Library[^] and you'll find more options with other similar functions. The pure .NET-way is just to request a network resource and handle
SocketException
orWebException
(often times theSocketException
is an inner-exception). This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]