Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Timer Not Working - Can Anyone Explain Why and How to fix?

Reply
Thread Tools

Timer Not Working - Can Anyone Explain Why and How to fix?

 
 
Sir Bill
Guest
Posts: n/a
 
      01-11-2006
I can not seem to get a system timer to work for me. Here is the code both
the aspx and aspx.vb file. The textbox displays "Timer Started" and never
anything else. What am I missing?


<%@ Page Language="VB" Debug="true" AutoEventWireup="false"
CodeFile="test.aspx.vb" Inherits="test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server">This is a text
box</asp:TextBox>
</div>
</form>
</body>
</html>
And the following codebehind file:
Imports System.Web.UI.WebControls
Partial Class test
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
If Not IsPostBack Then
CreateTimer()
Dim myTxt As WebControls.TextBox
myTxt = Form.FindControl("TextBox1")
myTxt.Text = "Timer Started"
End If
End Sub
Private Sub CreateTimer()
Dim Timer1 As New System.Timers.Timer
Timer1.Interval = 5000
Timer1.Enabled = True
AddHandler Timer1.Elapsed, New
System.Timers.ElapsedEventHandler(AddressOf Me.Timer1_elapsed)
End Sub
Private Sub Timer1_elapsed(ByVal sender As System.Object, ByVal e As
System.Timers.ElapsedEventArgs)
Dim myText As WebControls.TextBox
myText = Form.FindControl("textbox1")
myText.Text = "Timer Popped " & Today.TimeOfDay.ToString
End Sub
End Class


 
Reply With Quote
 
 
 
 
Luke Zhang [MSFT]
Guest
Posts: n/a
 
      01-12-2006
Hello Bill,

This is caused the Timer you define on server side wouldn't worked on
controls on client side. When you execute following code on server:

CreateTimer()
Dim myTxt As WebControls.TextBox
myTxt = Form.FindControl("TextBox1")
myTxt.Text = "Timer Started"

The server will create a new thread to execute code in Timer and run
remained code right away:

Dim myTxt As WebControls.TextBox
myTxt = Form.FindControl("TextBox1")
myTxt.Text = "Timer Started"

Then it sent full response to client. Even the code in the new thread was
finished, it won't send response to client side and the controls on client
won't be updated. In ASP.NET, we cannot use Timer like a Windows Form
application.

Luke


 
Reply With Quote
 
 
 
 
Sir Bill
Guest
Posts: n/a
 
      01-12-2006
OK, I want change the source of an image at intervals. How do I do that. I
thought a timer would do it.


"Luke Zhang [MSFT]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello Bill,
>
> This is caused the Timer you define on server side wouldn't worked on
> controls on client side. When you execute following code on server:
>
> CreateTimer()
> Dim myTxt As WebControls.TextBox
> myTxt = Form.FindControl("TextBox1")
> myTxt.Text = "Timer Started"
>
> The server will create a new thread to execute code in Timer and run
> remained code right away:
>
> Dim myTxt As WebControls.TextBox
> myTxt = Form.FindControl("TextBox1")
> myTxt.Text = "Timer Started"
>
> Then it sent full response to client. Even the code in the new thread was
> finished, it won't send response to client side and the controls on client
> won't be updated. In ASP.NET, we cannot use Timer like a Windows Form
> application.
>
> Luke
>
>



 
Reply With Quote
 
Scott Allen
Guest
Posts: n/a
 
      01-12-2006
On Wed, 11 Jan 2006 17:58:53 -0600, "Sir Bill"
<(E-Mail Removed)> wrote:

>I can not seem to get a system timer to work for me. Here is the code both
>the aspx and aspx.vb file. The textbox displays "Timer Started" and never
>anything else. What am I missing?
>
>


A web page tries to execute as quickly as possible, and then it's done
and gone. It's not like a Windows form, that sticks around, takes user
input, and waits for timers. It is born, it renders, it's gone...

--
Scott
http://www.OdeToCode.com/blogs/scott/
 
Reply With Quote
 
Luke Zhang [MSFT]
Guest
Posts: n/a
 
      01-12-2006
A quick and easy solution is a GIF image with multiple frame instead.

Luke

 
Reply With Quote
 
Scott Allen
Guest
Posts: n/a
 
      01-12-2006
On Wed, 11 Jan 2006 20:50:56 -0600, "Sir Bill"
<(E-Mail Removed)> wrote:

>OK, I want change the source of an image at intervals. How do I do that. I
>thought a timer would do it.
>
>


Another populat approach is a timer running in the client's browser
with JavaScript:
http://www.google.com/search?hl=en&q...e+timer+rotate

--
Scott
http://www.OdeToCode.com/blogs/scott/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
System.Timers.Timer/System.Threading.Timer Not Firing At All on Dev Server james.e.coleman@gmail.com ASP .Net 1 02-22-2005 09:41 PM
Can anyone explain why this doesn't work? Iver Erling Årva Javascript 4 09-15-2004 07:40 AM
Can anyone explain why output is garbage for char in a union in this code ? Sid C++ 3 07-16-2004 09:26 AM
Can anyone explain why paging does not work if AutoGenerateColumns = false!!?!?!?!?! pietaster ASP .Net Datagrid Control 1 10-28-2003 03:42 PM



Advertisments