Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Add elaspedEvent to System.timer

Posted on 2006-07-06
3
Medium Priority
?
218 Views
Last Modified: 2008-02-01
Hi, i have created a Dim myTimer as new System.timer(1000) .

Now i have a function which i wants the timer to call every 1sec. How do i write the code for tell the timer which function to call when there's an elapsedEvent.

Assumming

Dim myTimer as New System.timer(1000) ' my timer created at run-time

Public Sub mySubProc()
'Do some stuffs here every 1 sec
End Sub

thanks
0
Comment
Question by:jaxrpc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 17

Expert Comment

by:ZeonFlash
ID: 17055840
First you have to start the timer, such as with a button click:

Private Sub button1_Click(sender As Object, e As System.EventArgs) Handles button1.Click
     myTimer.Enabled = True
End Sub

Then you have to catch the Timer tick event:

Private Sub myTimer_Tick(sender As Object, e As System.EventArgs) Handles myTimer.Tick
   mySubProc()
End Sub
0
 

Author Comment

by:jaxrpc
ID: 17055960
hmm what if i want to do it programmatically, like adding delegate event programmatically.

like initialise a new system.timer()
and when it starts it will call an event.

And i might need to initalise an array of timers.
0
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 17056025
Hi jaxrpc;

This sample code will show you how to do it.

    ' Reference to Timer
    Private myTimer As Timer

    Private Sub Button1_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button1.Click

        ' Create timer in code
        myTimer = New Timer
        myTimer.Interval = 1000
        myTimer.Enabled = True
        ' Add Handler for the tick event
        AddHandler myTimer.Tick, AddressOf myTimer_Tick
        myTimer.Start()

    End Sub

    ' Tick event handler for the timer
    Private Sub myTimer_Tick(ByVal sender As Object, _
        ByVal e As System.EventArgs)

        mySubProc()

    End Sub

    ' Function timer calles.
    Public Sub mySubProc()
        'Do some stuffs here every 1 sec
    End Sub


Fernando
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question