首页 > 代码库 > WPF 检测计算机网络连接情况

WPF 检测计算机网络连接情况

 1   public static class NetWork 2     { 3         [DllImport("wininet.dll")] 4         private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue); 5  6         public static bool IsOnLine() 7         { 8             try 9             {10                 var connection = 0;11                 return InternetGetConnectedState(out connection, 0);12             }13             catch (Exception)14             {15              throw;16             }17         }18     }