Home Page - www.tele-pro.co.uk - Ecommerce Integration


Scripts > Schedule Task in ASP

Scheduled Task in Active Server Pages

This useful re-usable function enables you to effectively schedule a task in an ASP application. The scheduled task is in the form of any ASP function.

NB: The scheduled function actually runs the first time after the specified time period that a visitor browses to the ASP page. If the Application is restarted, the specified function is also executed immediately.

Using the Schedule Task function

The function definition looks like this: ScheduleTask(task_name, period, qty)

It returns a boolean result of True if the scheduled task is due to be run immediately, otherwise returns False.

task_name
A unique string for the name for your task, e.g, "MyTask1". The timestamp of the last time the task was run is stored in an application variable based on this name.

period
The period parameter specified must be one of the Date constants

qty
The number of intervals between tasks, with the interval as specified by the value of the period parameter.

Schedule Task Example Code

In the code below, the function AnyFunction will run every 6 hours. The timestamp of the last time this task was run, will be stored in an application variable called Sched_MyTaskName

'call AnyFunction() once every 6 hrs
If (ScheduleTask("MyTaskName", "h", 6)) Then
  Call AnyFunction()
end If

FUNCTION ScheduleTask(task_name, period, qty)
  Dim RunNow
  Dim last_date
  Dim diff

  'boolean result
  RunNow = False

  'chcek the value of app setting
  last_date = Trim(Application("Sched_" & task_name))

  'is value empty? maybe app just started
  If (last_date = "") Then
    RunNow = True
  Else
    'is value old?
    diff = DateDiff(period, last_date, Now())
    If (diff>=qty) Then RunNow = True
  End if

  'if scheduled to run now, set the app last run time
  If (RunNow) Then Application("Sched_" & task_name) = Now()

  'return result
  ScheduleTask = RunNow
END FUNCTION

FUNCTION AnyFunction()
'your code here
END FUNCTION
 

Download code as text


Date Constants
SETTING DESCRIPTION
YYYY Year
Q Quarter
M Month
Y Day Of Year
D Day
W WeekDay
WW Week Of Year
H Hour
N Minute
S Second

 

If you like this script, please rate it at HotScripts:

Other HotScripts Links:

 Go Stored Documents HotScripts - Scheduled Task in ASP
 Go Appointment Booking System
 Go Internet Explorer Password Recovery
 Go RSS XML Content Feed VBScript Class
 Go ASP Session Transfer across domains
 Go Website Contact Form Generator
 Go WS_FTP Password Reminder
 

See Also

 Go Free Scripts
 Go Commercial Scripts
 Go Other Developer Websites
 Go Scripts Made to Order
 Go Request Programming Quote
 Go Contact Form Generator
 

Keywords

script, program, free scripts, programming, code, application, utility, javascript, active server pages, asp, asp.net, sql, flash, xml, vbscript, sql, cgi, perl, php, php3, delphi, dhtml, web development, database, resources, unix, wsh, outlook, office automation, ecommerce, remotely hosted, website design
 

Your Feedback is Important

Why not let us know your feedback, or any suggestions you have? Your opinion and feedback is very important to us and to future website visitors, as it enables the continual improvement of products, services, scripts and software available from this website.

Anonymous

Top | Home | ECommerce | Hosting | Site Map | Search | © 2003-6 | Contact