473,408 Members | 2,839 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,408 software developers and data experts.

System.Timers.Timer

Rob
I've got the following skeleton in my HttpApplication (global.aspx) file:

Public Sub New()
MyBase.New()
ApplicationTimer = New System.Timers.Timer
ApplicationTimer.BeginInit()
ApplicationTimer.Interval = 60 * 1000 ' 60 seconds
ApplicationTimer.Enabled = True
ApplicationTimer.EndInit()
End Sub

Private Sub ApplicationTimer_Elapsed(ByVal sender As Object, ByVal e
As System.Timers.ElapsedEventArgs) Handles ApplicationTimer.Elapsed
' Do something time consuming
End Sub

Is ApplicationTimer_Elapsed run on a separate thread to those processing
HTTP requests? The reason I ask is that the code I'm about to drop into
ApplicationTimer_Elapsed takes several seconds to run. It's sending an email
via SmtpClient.Send(MailMessage) which doesn't seem to return until the
email has been sent.

I don't want this operation to slow up supplying pages to users of the
system requesting web pages.

Thanks, Rob.
Sep 26 '07 #1
2 2131
when a request starts, a processing thread is picked from the pool.
the request thread first job is to get an application object from the
application object pool. if none are free it creates one. when the
request finishes, the application object and request threads are
returned to their pools.

your timer will alway be running on a request thread, and may block any
request. if the same request thread creates two application objects
(different request same thread), then the time will be runnning more
than once on the same thread. it can also be running on two threads.

any response.end aborts the current request thread and will stop any
timer you started on that thread.

you probably want to start one background thread to do this. use locks
and a static or application start to only start only one background thread.

-- bruce (sqlwork.com)

Rob wrote:
I've got the following skeleton in my HttpApplication (global.aspx) file:

Public Sub New()
MyBase.New()
ApplicationTimer = New System.Timers.Timer
ApplicationTimer.BeginInit()
ApplicationTimer.Interval = 60 * 1000 ' 60 seconds
ApplicationTimer.Enabled = True
ApplicationTimer.EndInit()
End Sub

Private Sub ApplicationTimer_Elapsed(ByVal sender As Object, ByVal e
As System.Timers.ElapsedEventArgs) Handles ApplicationTimer.Elapsed
' Do something time consuming
End Sub

Is ApplicationTimer_Elapsed run on a separate thread to those processing
HTTP requests? The reason I ask is that the code I'm about to drop into
ApplicationTimer_Elapsed takes several seconds to run. It's sending an email
via SmtpClient.Send(MailMessage) which doesn't seem to return until the
email has been sent.

I don't want this operation to slow up supplying pages to users of the
system requesting web pages.

Thanks, Rob.

Sep 26 '07 #2
Rob
when a request starts, a processing thread is picked from the pool.

I don't think this is an HTTP request - it's the core webapp's application
object, inherited from HttpApplication. It's called global.aspx but I think
that's a hangover from ASP v1, it can be called anything in ASP v2.

So I'm assuming that I'm adding a timer to the main application thread so I
wouldn't expect the request thread pool to be involved. But I am guessing.

Having an event take several seconds to run doesn't appear to cause dealing
of requests to slow significantly, i.e. the processing of requests via the
thread pool carries on as normal.

Cheers, Rob.
Sep 29 '07 #3

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

Similar topics

3
by: Peter Johnsson | last post by:
How come the eventhandler for the timer's elapsed time event is called over and over again, even though the AutoReset property is set to false, if you assign a new value to the timer objects...
9
by: Mark Rae | last post by:
Hi, I've seen several articles about using System Timers in ASP.NET solutions, specifically setting them up in Global.asax' Application_OnStart event. I'm thinking about the scenario where I...
10
by: WhiteSocksGuy | last post by:
Help! I am new to Visual Basic .Net (version 2002) and I am trying to get a System.Timers.Timer to work for me to display a splash screen for about two seconds and then load the main form. I have...
5
by: Michael C# | last post by:
Hi all, I set up a System.Timers.Time in my app. The code basically just updates the screen, but since the processing performed is so CPU-intensive, I wanted to make sure it gets updated...
1
by: melanieab | last post by:
Hi, I'm have a datagrid, and I'm trying to have a tooltip pop up if a cell has been hovered on for 2 seconds. I was thinking of using DataGrid.Hover, but then decided to try this instead: ...
2
by: cntams | last post by:
All, I have a Windows Service and it has one System.Timers.Timer that fires every 500 milliseconds. Now I have noticed that there's a bug in System.Timers.Timer when it's being used combined with...
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: Tony Gravagno | last post by:
I have a class that instantiates two Timer objects that fire at different intervals. My class can be instantiated within a Windows Form or from a Windows Service. Actions performed by one of the...
2
by: BobAtVandy | last post by:
I'll greatly appreciate any help on this. Actually 2 questions: 1. I believe I need to use the Windows timer System.Timers.Timer . The examples I find on the web all access that timer by...
8
by: Ollie Riches | last post by:
I'm looking into a production issue related to a windows service and System.Timers.Timer. The background is the windows service uses a System.Timers.Timer to periodically poll a directory location...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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...
0
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,...

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.