Google "cfthread", or look it up in the docs. That will do what you need.
Okay, thank you.
I'll test it.
I tested cfthread, but still I have the same problem like before(page timeout).
Here is what I do:
Start Database procedure to create a data export file. It will be saved on the server.
<cfthread name="t1" action="run" priority="normal">
<cfstoredproc procedure="exp" datasource="test" returncode="no" >
<cfprocparam type="in" dbvarname="id" cfsqltype="cf_sql_integer" value="#url.id#">
When the procedure finished, (this can take some minutes), the export file is opened.
If it is a big export I get a page timeout. If the export is fast enough a popup window opens to download or
open the file.
<cfthread name="t1" action="join" />
<cfcontent type = "text/plain"
file = "export"
deleteFile = "no">
What's wrong with my code? How to tell the page to wait until the procedure is finished and not to get a timeout?
If you have a request timeout set in CFAdmin, then that will be enforced irrespective of how the code is called. If you need more time than that, you can override it with CFSETTING.
I think you misunderstand what it is you're doing - it looks to me as if you're trying to get the file downloaded to the browser once it's finished?
Yes, the CFTHREAD tag is running it in the background, but you're then doing a <cfthread action="join">, which makes the main thread wait for the other one to finish, rendering the other thread essentially pointless. All you're doing is making on thread wait whilst another does the work, which is only useful if you're doing more than one thing at once. It looks there like you're only doing one task, so having more than one thread is pointless.
You have two choices - run the proc in your main thread and get output to the screen afterwards (as you are now), or run it in a different thread but accept you have severed all ties between the page and the running thread - you cannot get a running background thread to suddenly come back and connect to someone's browser once their page has loaded.
Also be aware that depending on what CF server you are using (standard, enterprise, etc) you may be limited to the number of threads that your CF server can have active at any given time. Its usually not a problem, but can cause unexpected problems if you are planning a high traffic application.