Tech Tip: Background Schedule Process
PRODUCT: 4D | VERSION: 2004 | PLATFORM: Mac & Win
Published On: July 23, 2008
It is common to have a method that needs to run at a certain interval. The sample code below executes a method every Sunday during the midnight hour. The time can easily be changed, but the idea behind the code stays the same.
Insert the following one line of code in the On startup database method:
C_LONGINT(proc) proc:=New process("test_everysunday";64*1024;"myprocess") |
Create a method named "test_everysunday" and insert the following code:
C_TIME($time) C_INTEGER($day) While(True) $time:=Current time\3600 `returns the hour $day:=Day number(Current date) `returns the day of week If (($day=1) & ($time=0)) `if it is midnight on sunday `insert a call to your method here End if DELAY PROCESS(Current process;216000) End while |
This code creates a background process which checks the date every time it wakes up. If it is not Sunday the process is delayed again. This is one example of how a background process can be used, there are many other ways to implement and use background processes.