I'm trying to have a bunch of code run on the hour every hour in my VB Application. The code works in it's own Sub, but when I add it to this "TopOfTheHour" Shared Sub I get the error "cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class"
I left in the loadlbl.Visible as an example of what doesn't work which is just a label control on my main Form (Form1). Writing the refresh time to the console works, but loadlbl.Visible = True does not.
Private Shared Sub OnTimedEvent(source As Object, e As System.Timers.ElapsedEventArgs)
Dim aTimer As System.Timers.Timer = CType(source, System.Timers.Timer)
aTimer.Stop()
Console.WriteLine("Server Status Refreshed at " & DateTime.Now)
loadlbl.Visible = True
'Far more code is here, much of it with the same error.
aTimer.Interval = MillisecondsToNextTopOfTheHour()
aTimer.Start()
End Sub
All my code for Form 1 (including what I want to add to this Shared Sub) is here on PasteBin. (VB Syntax Highlighting is on so code is easier to read)
Thank You!
Do you really need this method to be 'shared'? Remove the shared and try again.
Shared means that is method is not an instance method, it has no access to any local variables.