Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
Hello.
I have a question about firing an event or call a method in a certain condition (eg if(datetime1 > datetime2) )

Basically I need to send birthday emails to someone registered on my website at his/her birthday at Midnight.

Then, each hour, I need to send a PM to me containing an updated log.


How do I do that?
I thought about using LINQ queries on masterpage, and if (DateTime.Now > Midnight) it calls a certain method. But it might slow down all the website.

Are there any solutions?
Posted

There's basically two options here.

Best is if you either own the server or are permitted to run a service or cron job (sorry, scheduled process ;) ) on it. Set the service up to check once an hour for anyone whose birthday tripped in the last hour, and send you a PM (i.e. write to a database table), or, equivalently, have the process which gets spawned every hour do that.

If you can't do that, and you can't persuade your host to let you do so, you can indeed check inside every request and do this sort of processing. For example my HTTP server class checks for session timeouts every request. This sort of processing needs to be very lightweight – a check before executing anything whether you did it this hour already.

Actually, thinking about it, an ASP.net web application runs in a persistent process. So you could potentially spawn a thread in App_Load which performed the same job as the service (though you will need to keep synchronisation issues in mind if you do that – but you should already be thread-safe as web requests are processed in parallel). That seems like not a very robust solution though, because there is no guarantee that IIS will keep your website in a single process indefinitely.
 
Share this answer
 
SQL
if (DateTime.Now > Midnight) counts for a complete day!
Better create a service that runs on midnight once for the birthday emails and hourly for the PM
 
Share this answer
 
Create a job that will execute at MidNight. Step To Create Job
Now in Job Find users which has birthday today and send email.
To send email use Database Email Here you find step to send email
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900