Hi,

I have a class called InternetDetector that is checking to see if internet is available, and if available, add a Label to a form.

I declare the class like this:

vb.net Code:
  1. Dim id As InternetDetector = New InternetDetector(2500, My.Settings.CheckInternetHostName, Me, _uiLanguage)
  2. id.Start()

That will give me a warning, saying that Access of shared member, constant member, enum member or nested type through an instance; qualifing expression will not be evaluated, and it suggest me to change my code to:

vb.net Code:
  1. Dim id As InternetDetector = New InternetDetector(2500, My.Settings.CheckInternetHostName, Me, _uiLanguage)
  2. InternetDetector.Start()

Both of them work, but how is it that InternetDetector.Start knows the parameters of id?

InternetDetector class:
vb.net Code:
  1. Option Strict On
  2. Option Explicit On
  3.  
  4. Imports System.Drawing
  5. Imports System.Windows.Forms
  6.  
  7. Public Class InternetDetector
  8.     Private Shared _host As String = Nothing
  9.     Private Shared _interval As Integer = 1000
  10.     Private Shared _form As Object = Nothing
  11.     Private Shared _uiLanguage As String = Nothing
  12.  
  13.     Public Sub New(ByVal interval As Integer, ByVal host As String, ByVal sender As Object, ByVal uiLanguage As String)
  14.         _host = host
  15.         _interval = interval
  16.         _form = sender
  17.         _uiLanguage = uiLanguage
  18.     End Sub
  19.  
  20.     Public Shared WithEvents checkTimer As New System.Timers.Timer(_interval)
  21.  
  22.     Public Shared Sub Start()
  23.         checkTimer.Start()
  24.  
  25.     End Sub
  26.  
  27.     Public Shared Sub [Stop]()
  28.         checkTimer.Stop()
  29.  
  30.     End Sub
  31.  
  32.     Public Shared Sub m_Timer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles checkTimer.Elapsed
  33.  
  34.         InternetDetector_Result(IsInternetIsAvailable(_host))
  35.  
  36.     End Sub
  37.  
  38.     Private Delegate Sub InternetDetector_ResultCallback(ByVal result As Boolean)
  39.     Private Shared Sub InternetDetector_Result(ByVal result As Boolean)
  40.         Dim f As Form = DirectCast(_form, Form)
  41.  
  42.         If f.InvokeRequired Then
  43.             f.Invoke(New InternetDetector_ResultCallback(AddressOf InternetDetector_Result), result)
  44.  
  45.  
  46.         Else
  47.             'Some crazy code to add a label to a form
  48.  
  49.         End If
  50.     End Sub
  51.  
  52.     Private Shared Function IsInternetIsAvailable(ByVal host As String) As Boolean
  53.         Try
  54.             Dim a As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry(host)
  55.             Return True
  56.  
  57.         Catch ex As System.Net.Sockets.SocketException
  58.             Return False
  59.  
  60.         End Try
  61.  
  62.     End Function
  63.  
  64. End Class