1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Can any one explain the code given below??... Its about the scheduling

Discussion in 'C#' started by rag84dec, Apr 2, 2008.

  1. #1
    
    <%@ LANGUAGE="VBScript" %>
    <% Option Explicit %>
    <%
    '+---------------------------------------------------+
    '| Scheduled Task in Active Server Pages             |
    '| Nick Sumner 06.2004                               |
    '| http://www.tele-pro.co.uk/                        |
    '| dev@nicksumner.com                                |
    '+---------------------------------------------------+
    '| asp_schedule_task.asp
    '| schedule a task in an ASP application
    '+---------------------------------------------------+
    
    
    '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 
    
    %>
    
    
    Code (markup):

    SEMrush
     
    rag84dec, Apr 2, 2008 IP
    SEMrush
  2. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,681
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What explaination do you want? The code checks an application variable and if the difference is greater than the amount noted in the function or if it cannot tell when it was last run it then says to run the function and sets the datetime of the last run as now.

    The problem with these types of functions is that it run on the assumption that the application will be running 24/7 however unless you have a constant stream of visitors or have a dedicated server the application will almost certainly be killed to release the memory back to the server thus a proc that is only to run every 24hrs or so will probably run several times in that period.

    The second issue is that it requires a page to be called to trigger the function so again will only work if there are a reasonable level of visitors (inc bots) otherwise if you have a script to run ever 5 minutes but you only get page calls on average ever hour then the script will only run on an hourly basis.

    Unfortunately IIS/ Windows shared hosting doesnt have the same capabilities as Cron jobs in the LAMP environment.... services are the solution for windows however most shared hosts wont install 3rd party services due to the security risk.
     
    AstarothSolutions, Apr 2, 2008 IP