473,654 Members | 2,968 Online
Bytes | Software Development & Data Engineering Community
+ 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.T imer 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********@hotm ail.com
http://www.nathansokalski.com/
Nov 19 '05 #1
5 4100
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.T imer 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********@hotm ail.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.T imer 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********@hotm ail.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.T imer in ASP.NET since
Visual Studio lets you add it to an ASP.NET webform.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/
"Anand[MVP]" <An******@discu ssions.microsof t.com> wrote in message
news:ED******** *************** ***********@mic rosoft.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.T imer 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********@hotm ail.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.Threadin g;
using System.Data;
using System.Data.Sql Client;
using System.Configur ation;

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

public void Init(HttpApplic ation application) {
// Wire-up application events
if (timer == null)
timer = new Timer(new
TimerCallback(S cheduledWorkCal lback),
application.Con text, interval, interval);
}

public void Dispose() {
timer = null;
}

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

void DoSomething (HttpContext context) {
}

#region DB Poll
void Poll (HttpContext context) {
SqlConnection connection = new
SqlConnection(C onfigurationSet tings.AppSettin gs["Northwind"]);
SqlCommand command = new
SqlCommand("SEL ECT * FROM changenotificat ion", connection);
SqlDataReader reader;
string key =
ConfigurationSe ttings.AppSetti ngs["SqlDepende ncy"];
connection.Open ();
reader = command.Execute Reader();
while (reader.Read()) {
string tableKey = String.Format(k ey, reader["Table"]);
if (context.Cache[tableKey] != null) {
int changeKey =
int.Parse( context.Cache[ String.Format(k ey,
reader["Table"])].ToString() );
if (changeKey != int.Parse(
reader["ChangeID"].ToString() ))
context.Cache.R emove(tableKey) ;
}
}
connection.Clos e();
}
#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.T imer in ASP.NET since
Visual Studio lets you add it to an ASP.NET webform.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/
"Anand[MVP]" <An******@discu ssions.microsof t.com> wrote in message
news:ED******** *************** ***********@mic rosoft.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.T imer 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********@hotm ail.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
319
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 AddHandler t.Elapsed, AddressOf TimerFired This in turns fires up my sub called "TimerFired" every 2 minutes... In this sub, I check a file for a change in the date/time and if I find a
8
2773
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 called? private System.Windows.Forms.Timer timerDF; this.timerDF = new System.Windows.Forms.Timer(this.components);
2
5154
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 I am new to this. Full code below : using System; using System.Collections; using System.ComponentModel;
7
2374
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 reset I put some extra code in the subs that enable and disable the timer. They fire as expected. To test this I added a second timer with a 1 second interval. The event for this time would output the enabled status of the first timer and its...
5
1616
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 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...
4
11110
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 the default of True. The Elapsed event handler updates the dialog box with how long before it will close, acting as a timer itself. The dialog has a time to close property which is checked every time the Elapsed event fires. The problem I have...
5
1794
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 false as i want to start processing only on user specified time. I am setting interval as difference between user sepcified time and current time. And when that elapsed event occured i am again setting
10
4278
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 will stop executing after 30 to 40 days. After learning this, I found the same issue had been documented in the the System.Threading.Timer class as well. This limits my options for having a timer based windows service using the .net framework....
10
1832
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 have been trying to make the program (wich has no UI) to keep running and let it execute everything once every few minutes (depending on how the timer is set). Can anyone tell me how I can get a timer in the program so the program keeps running?...
0
8372
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8706
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8475
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7304
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6160
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4293
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2709
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
1915
muto222
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.