Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static bool IsInternetSlow()
- {
- return NetworkInterface.GetIsNetworkAvailable();
- }
- public static bool IsInternet()
- {
- ConnectionProfile connections = NetworkInformation.GetInternetConnectionProfile();
- bool internet = connections != null && connections.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess;
- return internet;
- }
- protected override void Test()
- {
- Stopwatch w = new Stopwatch();
- w.Start();
- for (int i = 0; i < 100; i++)
- {
- bool isInternet = IsInternetSlow();
- }
- w.Stop();
- Debug.WriteLine("Slow method: {0}", w.Elapsed);
- w.Reset();
- w.Start();
- for (int i = 0; i < 100; i++)
- {
- bool isInternet = IsInternet();
- }
- w.Stop();
- Debug.WriteLine("Fast method: {0}", w.Elapsed);
- }
- /////////////////////////////
- Slow method: 00:00:17.1382156
- Fast method: 00:00:01.5759819
Advertisement
Add Comment
Please, Sign In to add comment