473,382 Members | 1,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

A web control timer that ticks - please help...

folks,

Please help. I'm trying to build a user defined control that displays
a time stamp that ticks. Here is what i have so far - it's using
threads but is not working. Can anyone help me please?
Thanks a million in advance.

Al

*******CODE**********
namespace Chapter_12
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Threading;

/// <summary>
/// Summary description for DateTimeUserControl.
/// </summary>
public class DateTimeUserControl : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.Label lblDateTimeStamp;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
Thread t = new Thread(new ThreadStart(timeThread));
t.Start();
Thread.Sleep(1000); //1 second

}
public void timeThread()
{
lblDateTimeStamp.Text = DateTime.Now.ToString();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}

Nov 17 '05 #1
2 1781
Hi Al

I'm not sure why your trying to use a server-side Timer on an asp.net page?
Timer's use up server resources, especially if you are telling it to sleep,
that could potentially tie up your requests. Also you cannot get an async
Timer to work with your web page in this way without doing postbacks to the
server.

I would recommend using the javascript "setTimeout" method on the client
side to create a timer to write to a control.
Nov 17 '05 #2
al*****@altavista.com wrote:
folks,

Please help. I'm trying to build a user defined control that displays
a time stamp that ticks. Here is what i have so far - it's using
threads but is not working. Can anyone help me please?
Thanks a million in advance.


I think you're taking the wrong approach here. I don't think threading
is going to buy you anything, all your doing is spawining a new thread
thats going out of scope as soon as the page load event completes.

Why not use javascript to implement your timestamp? In page load issue
a RegisterClientScriptBlock("clientScript", scriptString) call, where
your timer code is in the javascript. There are plenty of timer
javascript examples out there.

--
Rob Schieber
Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: David | last post by:
Hi There! I'm using Timer control to record how long my application perform certain tasks. However, apparently Timer control is not doing its' job (i.e. Not firing Tick event) while my...
8
by: bearophileHUGS | last post by:
Hello, I have four things to ask or to suggest, sorry if they seem basic or already discussed. ------------------- I am still ignorant about Tkinter. This little program, after pressing the...
0
by: Chris Millar | last post by:
I have a user control that i wish to extend to change the date when the user selects the numeric up down button. The code explains itself, hope someone can help. any ideas appreaciated.. ...
9
by: HL | last post by:
I am using VS 2005 Beta - C# Problem: The Timer fires a few milliseconds before the actual Due-Time Let's say a timer is created in the following manner: System.Threading.Timer m_timer = null;...
6
by: Steve | last post by:
I am working on a emulator and need to have time based events. I've tried to use the timer control and discovered that it runs waaaaaaay slow. I set the tick frequency to 1, then in the tick...
0
by: John Mason | last post by:
Hello, I have a small client app using a timer control that communicates with a Windows service using .NET remoting. Both apps were authored against the 1.1.4322 framework. The timer controls...
5
by: lucius | last post by:
With ASP.NET/Framework 1.1, I would like to have a class that instances on application startup, and every 60 seconds after that does some work (actually a database fetch). Then any .aspx/.asmx page...
1
by: Joseph Gruber | last post by:
Hi all. I'm looking for some help here. My app creates a runtime label which is used as a clock -- it also then creates the timer for this clock at runtime. When the timer tick's clockUpdate is...
19
by: colin | last post by:
Hi, Im trying to time some parts of my code using the Stopwatch class, but it is so slow, I tried the QueryPerformanceFrequency() but this seems to be just as slow, if I just simply call this...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.