views:

195

answers:

3

Hai guys, My website has thousands of users... I have implemented a background task of sending mails to every user once a day ... I followed this link to do this...

http://www.codeproject.com/KB/aspnet/ASPNETService.aspx

My question is will Application_Start() will be fired for every user hitting my website... If so every user will be receiving a n number of mails daily so i want to avoid it...

A: 

Application_Start only runs when the first person goes to the site and when the app_pool refreshes.

It does not happen on every hit to the site.

you might want to think of something like http://www.webcron.org/ for a cron-like system to schedule tasks.

John Boker
Maybe OP is thinking of _BeginRequest?
Michael Haren
Hi john, I am on shared hosting so i cant use schedulers ... Is it safe to use cache item callbacks and send mails once in aday for my users
Pandiya Chendur
Cache item callbacks cannot be relied on, the cache might be expired prematurely because the app needs memory or something, if i were you i'd try maybe using http://www.webcron.org/ or a similar site.
John Boker
+1  A: 

Hi,

The Application_Start and Application_End methods are special methods that do not represent HttpApplication events. ASP.NET calls them once for the lifetime of the application domain, not for each HttpApplication instance.

So When first user will open the site it will hit the application_start method after that it will not.

I will add that what you are trying to do is risky. If you want to do batch email sending then you may want to think about Scheduler which can send emails daily.

Ved
Hi ved i am on shared hosting they wont allow schedulers
Pandiya Chendur
A: 

It should be on the Application_BeginRequest plus a DB storing the state for every visitor. But the most appropriate is on Scheduler.

jerjer
Hai jerjer thanks for ur reply
Pandiya Chendur