473,471 Members | 2,040 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Timer.Elapsed event doesn't want to fire

I am trying to learn how to use the System.Timers.Timer control to perform
an action every certain amount of time. However, the Elapsed event doesn't
want to fire, but I can't figure out why. I looked at several code examples
online, but I think I was doing everything the same way they were. Does
anybody have a complete example in VB.NET (the whole aspx and aspx.vb file
so I know I am including everything) that I can look at? Any help would be
appreciated. Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Nov 19 '05 #1
5 4089
Are you trying to use this in a ASP.NET Page? Pages live only for the time of
the request. Once a request is served, the Page class is destroyed.

--
Rgds,
Anand
VB.NET MVP
http://www.dotnetindia.com
"Nathan Sokalski" wrote:
I am trying to learn how to use the System.Timers.Timer control to perform
an action every certain amount of time. However, the Elapsed event doesn't
want to fire, but I can't figure out why. I looked at several code examples
online, but I think I was doing everything the same way they were. Does
anybody have a complete example in VB.NET (the whole aspx and aspx.vb file
so I know I am including everything) that I can look at? Any help would be
appreciated. Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

Nov 19 '05 #2
for asp.net, anand is correct.

for all languages in general, timers are not guaranteed to fire on
time. this happens for two reason: 1) task switching at the CPU; and
2) WM_TIMER messages have a lower priority than other messages (like
device input)

Nov 19 '05 #3
hi, there are two types of timers, one is at windows forms, and the other is
at components, one works just fine, and the other its just crap... i didnt
know the difference, but so is it...
salute!

"Nathan Sokalski" wrote:
I am trying to learn how to use the System.Timers.Timer control to perform
an action every certain amount of time. However, the Elapsed event doesn't
want to fire, but I can't figure out why. I looked at several code examples
online, but I think I was doing everything the same way they were. Does
anybody have a complete example in VB.NET (the whole aspx and aspx.vb file
so I know I am including everything) that I can look at? Any help would be
appreciated. Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

Nov 19 '05 #4
I understand that that is true for the actual pages, but is there a way to
use a timer in the Global.asax.vb file? Doesn't that live the entire life of
the application? My basic goal is to find a way to periodically send myself
stats about what people do at my site, and send email newsletters. And there
is obviously some purpose for the System.Timers.Timer in ASP.NET since
Visual Studio lets you add it to an ASP.NET webform.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
"Anand[MVP]" <An******@discussions.microsoft.com> wrote in message
news:ED**********************************@microsof t.com...
Are you trying to use this in a ASP.NET Page? Pages live only for the time
of
the request. Once a request is served, the Page class is destroyed.

--
Rgds,
Anand
VB.NET MVP
http://www.dotnetindia.com
"Nathan Sokalski" wrote:
I am trying to learn how to use the System.Timers.Timer control to
perform
an action every certain amount of time. However, the Elapsed event
doesn't
want to fire, but I can't figure out why. I looked at several code
examples
online, but I think I was doing everything the same way they were. Does
anybody have a complete example in VB.NET (the whole aspx and aspx.vb
file
so I know I am including everything) that I can look at? Any help would
be
appreciated. Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

Nov 19 '05 #5
Here is an example. for the full context, see:
http://www.eggheadcafe.com/articles/20040607.asp
Hope this helps.
--Peter

using System;
using System.Web;
using System.Threading;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace BlackbeltBLL {
public class BackgroundService : IHttpModule {
static Timer timer;
int interval = 5000;
public String ModuleName {
get { return "BackgroundService"; }
}

public void Init(HttpApplication application) {
// Wire-up application events
if (timer == null)
timer = new Timer(new
TimerCallback(ScheduledWorkCallback),
application.Context, interval, interval);
}

public void Dispose() {
timer = null;
}

private void ScheduledWorkCallback (object sender) {
HttpContext context = (HttpContext) sender;
Poll(context);
}

void DoSomething (HttpContext context) {
}

#region DB Poll
void Poll (HttpContext context) {
SqlConnection connection = new
SqlConnection(ConfigurationSettings.AppSettings["Northwind"]);
SqlCommand command = new
SqlCommand("SELECT * FROM changenotification", connection);
SqlDataReader reader;
string key =
ConfigurationSettings.AppSettings["SqlDependency"];
connection.Open();
reader = command.ExecuteReader();
while (reader.Read()) {
string tableKey = String.Format(key, reader["Table"]);
if (context.Cache[tableKey] != null) {
int changeKey =
int.Parse( context.Cache[ String.Format(key,
reader["Table"])].ToString() );
if (changeKey != int.Parse(
reader["ChangeID"].ToString() ))
context.Cache.Remove(tableKey);
}
}
connection.Close();
}
#endregion
}
}
Nathan Sokalski wrote:
I understand that that is true for the actual pages, but is there a way to
use a timer in the Global.asax.vb file? Doesn't that live the entire life of
the application? My basic goal is to find a way to periodically send myself
stats about what people do at my site, and send email newsletters. And there
is obviously some purpose for the System.Timers.Timer in ASP.NET since
Visual Studio lets you add it to an ASP.NET webform.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
"Anand[MVP]" <An******@discussions.microsoft.com> wrote in message
news:ED**********************************@microsof t.com...
Are you trying to use this in a ASP.NET Page? Pages live only for the time
of
the request. Once a request is served, the Page class is destroyed.

--
Rgds,
Anand
VB.NET MVP
http://www.dotnetindia.com
"Nathan Sokalski" wrote:
I am trying to learn how to use the System.Timers.Timer control to
perform
an action every certain amount of time. However, the Elapsed event
doesn't
want to fire, but I can't figure out why. I looked at several code
examples
online, but I think I was doing everything the same way they were. Does
anybody have a complete example in VB.NET (the whole aspx and aspx.vb
file
so I know I am including everything) that I can look at? Any help would
be
appreciated. Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/


Nov 19 '05 #6

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

Similar topics

3
by: Mr. B | last post by:
My current app has a timer that I kick ON in my Form1_Load as follows: ' Set Up the Timer Function Dim t As New System.Timers.Timer(12000) ' 1000 = 1 Second t.Enabled = True ' False to Turn OFF...
8
by: Daniel P. | last post by:
I'm trying to set a timer that gets called every 3 seconds so I can update a field in the UI with the time elapsed since the process started. What am I doing wrong that timerDF_Tick does not get...
2
by: Besta | last post by:
Hello all, I am having trouble creating a windows service with a timer. Everything seems to go ok but the elapsed event does not fire.Can anyone shed any light on this, may be something simple as...
7
by: Noozer | last post by:
I have a timer on a form. It isn't firing at all. I know that the timer is enabled, and that the interval is low (4000, which should be 4 seconds). To ensure the timer wasn't being inadvertantly...
5
by: Nathan Sokalski | last post by:
I am trying to learn how to use the System.Timers.Timer control to perform an action every certain amount of time. However, the Elapsed event doesn't want to fire, but I can't figure out why. I...
4
by: Liverpool fan | last post by:
I have a windows application written using VB .NET that encompasses a countdown timer modal dialog. The timer is a System.Timers.Timer with an interval of 1 second. AutoReset is not set so accepts...
5
by: archana | last post by:
Hi all, I am using timer to do some functionality on user specified time. I am using system.timers.timer class and its timer to do this functionality. What i am doing is i set autoreset to...
10
by: igor | last post by:
I have recently discovered that the system.Timers.Timer from.Net Framework v1.1 is not reliable when used on Windows 2003 server. When incorporated into a Windows Service, the timer_elapsed event...
10
by: Joris De Groote | last post by:
Hi, I have wrote a program that checks for files and moves these files to the correct folders when they come in. Everything works fine. However I always have to start that program manually. I...
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...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.