473,587 Members | 2,448 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.W ebControls;
using System.Web.UI.H tmlControls;
using System.Threadin g;

/// <summary>
/// Summary description for DateTimeUserCon trol.
/// </summary>
public class DateTimeUserCon trol : System.Web.UI.U serControl
{
protected System.Web.UI.W ebControls.Labe l lblDateTimeStam p;

private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
Thread t = new Thread(new ThreadStart(tim eThread));
t.Start();
Thread.Sleep(10 00); //1 second

}
public void timeThread()
{
lblDateTimeStam p.Text = DateTime.Now.To String();
}
#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

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

}
#endregion
}
}

Nov 17 '05 #1
2 1794
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*****@altavis ta.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 RegisterClientS criptBlock("cli entScript", 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
1861
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 application is busy. So even if my application took 2 mins, the label that is used to show the number of seconds elapsed will still say "2 seconds".
8
2165
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 "Go" eats more and more RAM, is it normal? Can it be avoided? (In normal programs this is isn't a real problem). ! import Tkinter
0
1919
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.. Chris. code :
9
7260
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; Let's declare a constant Int32 m_TimePeriod = 10000;
6
2212
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 event I update a label on my form, nothing else. just counting in my head I have determined that it take roughly 14 seconds to get through 1000 ticks...
0
890
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 the periodicity for refreshing the details/progress of the Windows service. This all works perfectly in my test environment running 1.1. The...
5
1428
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 could go to that global instance instead of fetching the data themselves. Can anyone show an example of how to best do this? A 2.0 example...
1
1328
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 called (through AddHandler) and I use Controls.Find to find the runtime label. This works somewhat except that it seem for every 3 out of 4 ticks...
19
5185
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 function in a loop it takes 21 ticks with a reported frequency of 3.5mhz its is about 6us wich is over 12k instructions on my 2ghz cpu. this negates...
0
7920
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7849
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6626
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5718
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5394
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1454
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1189
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.