Timers with ASP.Net

Discussion in 'ASP.NET / ASP.NET Core' started by Alfageek, Dec 3, 2003.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Can you use System.Timers.Timer components in ASP.Net apps? I initialize my timer as:
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    Dim aTimer As System.Timers.Timer
    aTimer = New System.Timers.Timer

    AddHandler aTimer.Elapsed, AddressOf OnTimer

    aTimer.Interval = 1000
    aTimer.Enabled = True
    aTimer.Start()

    End Sub

    And have an event handler:

    Public Sub OnTimer(ByVal source As Object, ByVal e As ElapsedEventArgs)
    Dim sTest As String = "This is a test message ... "
    Dim txtTemp As String = ""
    Dim iNumber As Integer = CType(txtTSNumber.Text, Integer)
    txtTemp = sTest.Substring(iNumber)
    txtTemp = txtTemp & Space(10)
    txtTemp = txtTemp & sTest.Substring(0, sTest.Length - iNumber)
    txtTemp = txtTemp.Substring(0, 50)
    txtTSNumber.Text = CType(iNumber + 1, String)
    If iNumber > 50 Then
    txtTSNumber.Text = "0"
    End If
    End Sub

    But nothing seems to happen. Any suggestions?
     
  2. Bruce

    Bruce DiscountASP.NET Staff

    I don't think you can use the timer class in asp.net app.

    I vaguely remember I had to do similar thing w/ timer in an ASP.net app but failed.

    quote:Originally posted by Alfageek

    Can you use System.Timers.Timer components in ASP.Net apps? I initialize my timer as:
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    Dim aTimer As System.Timers.Timer
    aTimer = New System.Timers.Timer

    AddHandler aTimer.Elapsed, AddressOf OnTimer

    aTimer.Interval = 1000
    aTimer.Enabled = True
    aTimer.Start()

    End Sub

    And have an event handler:

    Public Sub OnTimer(ByVal source As Object, ByVal e As ElapsedEventArgs)
    Dim sTest As String = "This is a test message ... "
    Dim txtTemp As String = ""
    Dim iNumber As Integer = CType(txtTSNumber.Text, Integer)
    txtTemp = sTest.Substring(iNumber)
    txtTemp = txtTemp & Space(10)
    txtTemp = txtTemp & sTest.Substring(0, sTest.Length - iNumber)
    txtTemp = txtTemp.Substring(0, 50)
    txtTSNumber.Text = CType(iNumber + 1, String)
    If iNumber > 50 Then
    txtTSNumber.Text = "0"
    End If
    End Sub

    But nothing seems to happen. Any suggestions?

    </blockquote id="quote"></font id="quote">
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page