Hi all
I wanna do something like timing with ASP.net(c#).
for example I specify a date for sending an email (or any other jobs).
How can I do this? I don't have any idea.
<html>
<head>
<title>Scheduling - Method 1</title>
</head>
<body>
<p>
This script will print out "Do Something!" at the
first request and then at the first request after midnight
every day.
</p>
<%
' The way it stands, the "Do Something" line will run the first
' time it's hit after the web server starts and then again every
' day at the first hit after midnight. If no one hits it for a
' day it won't run until hit. This can be troublesome when
' you're doing a calculation which expects a day to have elapsed.
' Along the same lines, to make it not run upon starting,
' uncomment this section:
'If Application("LastScheduledRun") = 0 Then
' ' Set the "LastScheduledRun" variable to something to
' ' satisfy the condition checked below. I'm setting it
' ' to the current time, hence making the computer think
' ' it just got done running it so there's no need to do
' ' so again.
' Application.Lock
' Application("LastScheduledRun") = Now()
' Application.UnLock
'End If
' Useful Debugging Lines:
'Response.Write Application("LastScheduledRun") & "<br />" & vbCrLf
'Response.Write Now() & "<br />" & vbCrLf
'Response.Write DateDiff("d", Application("LastScheduledRun"), Now()) _
' & "<br />" & vbCrLf
' DateDiff works a little differently than you might expect. If
' you ask for the difference in days, it does not check to see
' how many days worth of time have elapsed between two dates,
' but simply takes the dates and subtracts them. Hence... from
' Jan 1, 2002, 11:59PM to Jan 2, 2002, 12:01AM returns 1 day even
' though in reality it's only been a couple seconds. This makes
' it ideal for triggering stuff at midnight like we're doing here.
'
' If days between "LastScheduledRun" and the current time is > 0,
' this must be the first hit after midnight so we run our daily
' routine. This condition is the key to what type of schedule is
' kept. It can be changed to hourly, every 10 minutes, or even
' the first hit after 5pm... whatever you want, but it won't ever
' run unless someone has hit the page containing it.
If DateDiff("d", Application("LastScheduledRun"), Now()) > 0 Then
' This is where you put the commands you want to run on the
' schedule set up by the above condition.
Response.Write "Do Something!"
' Reset our "LastScheduledRun" variable to the current date
' and time indicating we just did it.
Application.Lock
Application("LastScheduledRun") = Now()
Application.UnLock
End If
%>
</body>
</html>