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:
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:
Both of them work, but how is it that InternetDetector.Start knows the parameters of id? :)
InternetDetector class:
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:
Dim id As InternetDetector = New InternetDetector(2500, My.Settings.CheckInternetHostName, Me, _uiLanguage) 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:
Dim id As InternetDetector = New InternetDetector(2500, My.Settings.CheckInternetHostName, Me, _uiLanguage) InternetDetector.Start()
Both of them work, but how is it that InternetDetector.Start knows the parameters of id? :)
InternetDetector class:
vb.net Code:
Option Strict On Option Explicit On Imports System.Drawing Imports System.Windows.Forms Public Class InternetDetector Private Shared _host As String = Nothing Private Shared _interval As Integer = 1000 Private Shared _form As Object = Nothing Private Shared _uiLanguage As String = Nothing Public Sub New(ByVal interval As Integer, ByVal host As String, ByVal sender As Object, ByVal uiLanguage As String) _host = host _interval = interval _form = sender _uiLanguage = uiLanguage End Sub Public Shared WithEvents checkTimer As New System.Timers.Timer(_interval) Public Shared Sub Start() checkTimer.Start() End Sub Public Shared Sub [Stop]() checkTimer.Stop() End Sub Public Shared Sub m_Timer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles checkTimer.Elapsed InternetDetector_Result(IsInternetIsAvailable(_host)) End Sub Private Delegate Sub InternetDetector_ResultCallback(ByVal result As Boolean) Private Shared Sub InternetDetector_Result(ByVal result As Boolean) Dim f As Form = DirectCast(_form, Form) If f.InvokeRequired Then f.Invoke(New InternetDetector_ResultCallback(AddressOf InternetDetector_Result), result) Else 'Some crazy code to add a label to a form End If End Sub Private Shared Function IsInternetIsAvailable(ByVal host As String) As Boolean Try Dim a As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry(host) Return True Catch ex As System.Net.Sockets.SocketException Return False End Try End Function End Class