Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / September 2007

Tip: Looking for answers? Try searching our database.

System.Timers.Timer

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rob - 26 Sep 2007 21:36 GMT
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.
bruce barker - 26 Sep 2007 23:33 GMT
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)

> I've got the following skeleton in my HttpApplication (global.aspx) file:
>
[quoted text clipped - 22 lines]
>
> Thanks, Rob.
Rob - 29 Sep 2007 14:29 GMT
> 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.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.