How can you detect if User IS ONLINE?
-
Does anyone know of a "clean" way to detect if a user is online? Code examples are appreciated.
-
Does anyone know of a "clean" way to detect if a user is online? Code examples are appreciated.
using System.Runtime.InteropServices; ... public class InternetConnection { [DllImport("wininet.dll")] public static extern bool InternetGetConnectedStateEx(out int lpdwFlags, byte[] szConn, int iConnSize, int dwReserved); /// /// Status da conexão /// public enum Status: int { /// /// Local system uses a modem to connect to the Internet. /// INTERNET_CONNECTION_MODEM = 1, /// /// Local system uses a local area network to connect to the Internet. /// INTERNET_CONNECTION_LAN = 2, /// /// Local system uses a proxy server to connect to the Internet. /// INTERNET_CONNECTION_PROXY = 4, /// /// Local system has RAS installed. /// INTERNET_RAS_INSTALLED = 16, /// /// Local system is in offline mode. /// INTERNET_CONNECTION_OFFLINE = 32, /// /// Local system has a valid connection to the Internet, but it might or might not be currently connected. /// INTERNET_CONNECTION_CONFIGURED = 64 } /// /// Returns true if connected /// public static bool Connected { get { bool bConn = false; int flags = 0; byte [] cName = new byte[512]; if(InternetGetConnectedStateEx(out flags, cName, 512, 0)) { bConn = true; } return bConn; } } public InternetConnection() { } } ... InternetConnection inet = new InternetConnection(); if(inet.Connected) { ... } else { // not connected }
Cheers, John