gearbolt Posted July 8, 2003 Posted July 8, 2003 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 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 Quote
JABE Posted July 8, 2003 Posted July 8, 2003 For non-Windows apps, use System.Timers.Timer. Also, give time for the timer to raise its Elapsed event. 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 An alternative to timers would be to use threads. Quote
gearbolt Posted July 8, 2003 Author Posted July 8, 2003 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 Quote
*Experts* mutant Posted July 8, 2003 *Experts* Posted July 8, 2003 Just use the Dispose() method of the timer, the GarbageCollector will take care of freeing up the memory. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.