asp.net - Send an email once an hour even though page refreshes every minute -
using vb.net , vs 2015 create asp.net site.
i have web page refreshes automatically every minute , shows status of several items. want able send email page every 60 minutes if error found. prefer use code within site have access sql server 2012 create db if needed.
i thought best way if there error on page call subroutine send email. stands happen every minute annoying. thought best way session variable cannot work out how send email once every 60 mins , stop when error no longer present , reset time 0.
the code below shows have far. wrapped case statement checking error.
'checks see if email needs sent select case session("sendemail") case nothing, 60, 120, 180 'send email case else 'do nothing end select session("sendemail") = session("sendemail") + 1
this should work after page has refreshed 60 times session variable match case statement need send emails until has resolved error , dont want hardcode list of numbers incrementing 60 each time in case statement.
you can use mod
operator divide 60 minutes , remainder, don't need check 60, 120, 180 etc.
msdn documentation on mod
dim minutes integer if not session("sendemail") nothing minutes = trycast(session("sendemail"), integer) else minutes = 0 end if 'checks see if email needs sent if (minutes mod 60) > 1 'send email minutes = 0 ' reset counter else minutes = minutes + 1 end if session("sendemail") = minutes
Comments
Post a Comment