Threading.Timer

Morgan Delvanna

New member
Joined
Nov 3, 2004
Messages
2
Location
Greater Toronto Area
Programming Experience
5-10
I'm new to ASP, what I'm trying to do is use a timer to page through a Datagrid. I had a button that moves through and I copied that code to the TimerCallBack event of the Timer.

The event runs a few times before the page finishes loading, and stops before the Datagrid loads so it doesn't even page through.

In my ASP Class is the following code

PublicClass Scoreboard

Inherits System.Web.UI.Page

Protected CurrentPage As System.Web.UI.WebControls.Label

Protected TotalPages As System.Web.UI.WebControls.Label

ProtectedWithEvents dgScoreboard As System.Web.UI.WebControls.DataGrid

Protected _currentPageNumber As Int32 = 1

ProtectedWithEvents lblError As System.Web.UI.WebControls.Label

ProtectedWithEvents btnClose As System.Web.UI.WebControls.Button

'Timers State Object

Class TimerState

Public counter AsInteger = 0

Public tmr As System.Threading.Timer = Nothing

Public enabled AsBoolean = False

EndClass

Private ts As TimerState = New TimerState


PrivateSub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load

If ts.tmr IsNothingThen

' first time through, create the timer

ts.tmr = New System.Threading.Timer(New System.Threading.TimerCallback(AddressOf OnTimer), ts, 1000, 1000)

EndIf

ts.enabled = True

BindTable()

EndSub

BindTable() is what rebinds the datagrid, and the callback event calls BindTable again.
 
Last edited:
Back
Top