8

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...

4 Answers 4

21

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.

2
  • Hi ved i am on shared hosting they wont allow schedulers
    – ACP
    Nov 25, 2009 at 3:14
  • Hi I have recently implemented backgroudn tasks running in website by converting website as "always on" site. There is a setting in application pool to do this. You may want to look into that
    – Zeus
    Sep 5, 2017 at 18:09
4

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.

3
  • Maybe OP is thinking of _BeginRequest? Nov 25, 2009 at 2:59
  • 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
    – ACP
    Nov 25, 2009 at 3:15
  • 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 webcron.org or a similar site.
    – John Boker
    Nov 25, 2009 at 3:17
2

For the full picture - here is list of all events which can be fired in global.asax:

http://aspalliance.com/1114_Understanding_the_Globalasax_file.3

0

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

0

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.