Results 1 to 3 of 3

Thread: System.Timer.Timers on aspx page: How to stop timer

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2003
    Location
    Malaysia
    Posts
    1

    Question System.Timer.Timers on aspx page: How to stop timer

    Hi,

    I need help regarding the timer. I’m developing a SMTP email program that will send out email periodically. My program has a webpage where user can start/stop timer to send out email. Once the user press on the ‘start timer button’ on webpage, my program will call the timer.vb class (this class will start the timer and handle elapsed event). Code as below:

    Private Sub btn_timer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_timer.Click

    btn_timer.Enabled = False
    timer1.startTimer(txt_interval.Text, txt_to.Text)

    End Sub

    My problem is I can’t stop the timer. Even after setting the timer.enabled = false, the timer is still running. I even tried putting the timer inside the aspx.vb file (instead of calling another class) but it is not working also.

    Private Sub btn_stop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_stop.Click
    btn_timer.Enabled = True
    timer1.stopTimer()
    End Sub

    I don’t know what goes wrong as this method works well in windows form. Would someone please guide me? Below are the codes for timer.vb: -

    Public Class timer
    Private emailadd As String = Nothing
    Private flag As Boolean = True
    Dim Timer1 As New System.Timers.Timer()

    Public Sub startTimer(ByVal interval As Integer, ByVal email As String)
    Timer1.Interval = interval
    Timer1.Enabled = True
    emailadd = email
    AddHandler Timer1.Elapsed, AddressOf Timer1_Elapsed
    End Sub

    Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) 'Handles Timer1.Elapsed
    Dim mail As New mailAdapter()
    mail.newMail(emailadd, "[email protected]")
    End Sub

    Public Sub stopTimer()
    Timer1.Enabled = False
    End Sub

    End Class


    Thanks!


  2. #2
    Hyperactive Member tommygrayson's Avatar
    Join Date
    Aug 2005
    Location
    In my Nissan Silvia
    Posts
    433

    Re: System.Timer.Timers on aspx page: How to stop timer

    Try setting you Timer1.Interval=0. It is the same as disabling your timer.

    If it does not work then the timer did not went to the event.

    Try to establish breakpoints so that you can trace where the process is going through.

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: System.Timer.Timers on aspx page: How to stop timer

    It's a web application. No timer. Don't use it.

    You should be using a windows service for this task if you want to use a timer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width