Hai guys, My website has thousands of users... I have implemente开发者_StackOverflowd 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...
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.
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.
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
It should be on the Application_BeginRequest plus a DB storing the state for every visitor. But the most appropriate is on Scheduler.
精彩评论