Issues with timer in asp.net app
When the user clicks on Authorize button I have to to keep checking the db every 2 seconds for a value. In case I get a value I have to show a panel for processing else i have to show user other message.

The way I have done it is not working. After the timer is stopped its not clear where the code goes.

My code is as under:

    Private aTimer As System.Timers.Timer
    Dim AuthID As Integer = 0
    Dim counter As Integer = 0
    Private thisLock As New Object
    Private AuthCode As String = "Nothing"
    Protected Sub btnAuthorize_Click(ByVal sender As Object, ByVal e As EventArgs) Handles    btnAuthorize.Click
        If ValidateForm() Then
            Dim dr As DataRow = Nothing
            dr = DataAccess.SaveAuthorization(txtAccuntNumber.Text, lblAmountFinance.Text)
            If dr("AuthorizationID") <> 0 Then
                AuthID = dr("AuthorizationID")
                dr = Nothing
                aTimer = New System.Timers.Timer(2000)
                aTimer.Start()
                AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
            End If
    'Code never goes to the lines below
            If AuthCode <> "" Then
                lblauthorizationAmmount.Text = lblAmountFinance.Text
                lblAuthorizationNumber.Text = AuthCode
                panelAuthorize.Visible = True
            End If

        End If
    End Sub
    Public Sub OnTimedEvent()
        SyncLock (thisLock)
            Dim dr As DataRow = Nothing
            dr = DataAccess.GetAuthorizationConfirmation(AuthID)
            AuthCode = dr("AuthCode")

            counter = counter + 1
            If counter > 1 Or AuthCode <> "" Then

                aTimer.Enabled = False
                aTimer.Stop()
                aTimer.Dispose()

            End If
        End SyncLock
    End Sub



Issues with timer in asp.net app
===

When the user clicks on Authorize button I have to to keep checking the db every 2 seconds for a value. In case I get a value I have to show a panel for processing else i have to show user other message.

The way I have done it is not working. After the timer is stopped its not clear where the code goes.

My code is as under:

    Private aTimer As System.Timers.Timer
    Dim AuthID As Integer = 0
    Dim counter As Integer = 0
    Private thisLock As New Object
    Private AuthCode As String = "Nothing"
    Protected Sub btnAuthorize_Click(ByVal sender As Object, ByVal e As EventArgs) Handles    btnAuthorize.Click
        If ValidateForm() Then
            Dim dr As DataRow = Nothing
            dr = DataAccess.SaveAuthorization(txtAccuntNumber.Text, lblAmountFinance.Text)
            If dr("AuthorizationID") <> 0 Then
                AuthID = dr("AuthorizationID")
                dr = Nothing
                aTimer = New System.Timers.Timer(2000)
                aTimer.Start()
                AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
            End If
    'Code never goes to the lines below
            If AuthCode <> "" Then
                lblauthorizationAmmount.Text = lblAmountFinance.Text
                lblAuthorizationNumber.Text = AuthCode
                panelAuthorize.Visible = True
            End If

        End If
    End Sub
    Public Sub OnTimedEvent()
        SyncLock (thisLock)
            Dim dr As DataRow = Nothing
            dr = DataAccess.GetAuthorizationConfirmation(AuthID)
            AuthCode = dr("AuthCode")

            counter = counter + 1
            If counter > 1 Or AuthCode <> "" Then

                aTimer.Enabled = False
                aTimer.Stop()
                aTimer.Dispose()

            End If
        End SyncLock
    End Sub


