Help with timers

gearbolt

Member
Joined
Mar 16, 2003
Messages
14
I am trying to load a form from my sub main function but the timer never fires can you tell what am i doing wrong.

Thanks


Code:
Public Class MainClass

Friend Shared WithEvents t As New Timer()

Public Shared Sub Main()

Dim cl As New MainClass()

t.Interval = 1
t.Enabled = True

cl.LoadSplash()

End Sub

Public Function LoadSplash()

t.Start()

End Function


Private Shared Sub t_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles t.Tick
MsgBox("Event")


End Sub

End Class


[CODE]

thanks
 
For non-Windows apps, use System.Timers.Timer. Also, give time for the timer to raise its Elapsed event.

[VB]
Public Class MainClass
Friend Shared WithEvents t As New System.Timers.Timer()

Public Shared Sub Main()

Dim cl As New MainClass()

t.Interval = 1
t.Enabled = True

cl.LoadSplash()
-Give timer chance to raise Elapsed event.
Console.WriteLine("Press any key to continue...")
Console.ReadLine()
End Sub

Public Function LoadSplash()

t.Start()

End Function


Private Shared Sub t_Tick(ByVal sender As Object, _
ByVal e As System.Timers.ElapsedEventArgs) Handles t.Elapsed
MsgBox("Event")
End Sub
End Class
[/VB]

An alternative to timers would be to use threads.
 
Thanks for the reply. I ran your code but I had to make a few modifactions since I was making a GUI App and not a Console App.

I have another question though.
Since the timer was created in code how do I clean it up after it has completed its job. do i just set the timer to nothing.

thanks again
 
Back
Top