Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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.

Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...