How do I make a template pause(sleep)?
There is no native sleep or pause function in CFML. But with CFMX you can easily leverage Java and take advantage of Java's sleep function. The following code snippet will sleep for 1,000 milliseconds (one second) between calls to getTickCount().
Before Sleep: #getTickCount()#<br>
<cfscript>
go_to = createObject("java", "java.lang.Thread");
go_to.sleep(1000); //sleep time in milliseconds
</cfscript>
After Sleep: #getTickCount()#
</cfoutput>
This question was written by Steve Gustafson.
It was last updated on February 22, 2006 at 12:00:25 PM EST.
CFML Referenced
<cfscript>
<cfoutput>
GetTickCount()
Categories
Comments
Comment made by Jamie Samland on February 22, 2006 at 11:29 AM
This is nice!! Before, I was doing conditional loops until enough time passed.
I have the tiniest of corrections, the close cfscript tag needs to be down one line or it's commented out.
Comment made by Raymond Camden on February 22, 2006 at 12:01 PM
Thanks, fixed.
Comment made by John Allen on February 27, 2006 at 9:34 PM
This rules.
Comment made by Kyle Hayes on March 22, 2006 at 5:43 PM
Very cool indeed! What is this useful for?
Comment made by Greg Cronkright on January 27, 2008 at 12:01 AM
Is this different than the CF8 function: <cfscript> sleep(1000); //sleep time in milliseconds </cfscript>
Comment made by Raymond Camden on January 27, 2008 at 3:37 PM
You are correct. Most of the site hasn't yet been updated for CF8 just yet. It will be a slow process. :)