I need an application to check the Internet connection on my computer user. If there is, an image is displayed, and if not, another image is displayed. Here is the code I used to make this work:
Private Sub Window_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded If NetworkInformation.NetworkInterface.GetIsNetworkAvailable Then Dim bi1 As New BitmapImage bi1.BeginInit() bi1.UriSource = New Uri("Images\greenbar.png", UriKind.Relative) bi1.EndInit() Image2.Source = bi1 Else Dim bi2 As New BitmapImage bi2.BeginInit() bi2.UriSource = New Uri("Images\redbar.png", UriKind.Relative) bi2.EndInit() Image2.Source = bi2 MessageBox.Show("INTERNET CONNECTION NOT DETECTED") MessageBox.Show("You must be connected to the internet to use some aspects of this application.") MessageBox.Show("Please re-establish connection to the Internet and try again, thank you.") Me.Close() End If End Sub
I decided to test this on my own computer by changing my default gateway (thereby, it looks like I lost the connection). But I realized that the code still showed that I was connected. Therefore, I think that this is only a test of the connectivity of the interface, which in this case is my connection to the router (this is true, I am connected to the router).
So the question is: how to check if the user PC is really connected to the Internet? I read an article. What is the best way to test your Internet connection using .NET? but this is in C # and I don't get it.
source share