Here is my methodology:
1. The report will have a predetermined filename (this is so I can check for its existence).
2. I start printing the report. Then I take them to a NetWebPage that has two parts. (technically, I take them to this page then do an ajax call to start printing, then do the following)
(a) A Message saying wait
(b) Javascript that calls the server and asks if the report is complete (being able to open the filename in write mode, means its been completed).
3. If the report is complete, I open it (with Javascript)
4. If the report took too long, i open another page saying its taking too long and it will arrive later.
Below is the javascript I use at step 2b. This code checks every 1.5 seconds, ten times, if it doesnt turn up by then, it checks every 5 seconds another 10 times, again it checks each 10 seconds another 10 times, if the report doesnt turn up by them it redirects to a NetWebPage called SlowReport which shows a message, telling them it will turn up later.
So if a report takes longer than 2:45 you'll get a message. The slower polling is to maximise responsivness at the begining and not waste server power if its taking longer.
The ReportWrap mentioned in the Javascript is where I take them when the report finishes. Mine is a bit more complicated than necessary as the report preview is placed in an iFrame, so the report can also be emailed at this point in time.
The GenReport function checks to see if the report has been completed.
packet.Append( '<script>'&CRLF)
packet.Append( 'var reportTimer = setInterval(CheckReportProgress,1500);'&CRLF)
packet.Append( 'var intCount=0;'&CRLF)
packet.Append( 'var reportfn='''&CLIP(Encode7Bit(lFilename))&''';'&CRLF)
packet.Append( 'function CheckReportProgress(){{'&CRLF)
packet.Append( 'var jqxhr = $.ajax({{url: "'&CLIP(lURL)&'/GenReport?f='&CLIP(Encode7Bit(lFilename))&'",dataType: "json",data: {{'&CRLF)
packet.Append( ' result : "name",'&CRLF)
packet.Append( ' value : "value" } } '&CRLF)
packet.Append( ' ).done (function(data) {{'&CRLF)
packet.Append( ' console.log(''Result: '' + data.result); ;'&CRLF)
packet.Append( ' if (data.result==1) {{'&CRLF)
packet.Append( ' clearInterval(reportTimer);'&CRLF)
packet.Append( ' document.getElementById(''openReport'').style.display = "block";'&CRLF)
packet.Append( ' location.href=''/ReportWrap?fn='&CLIP(Encode7Bit(ReplaceBackSlashWithSlash(lFilename)))&''';'&CRLF)
packet.Append( ' } else {{'&CRLF)
packet.Append( ' intCount++;'&CRLF)
packet.Append( ' if (intCount>30) {{;'&CRLF)
packet.Append( ' clearInterval(reportTimer);'&CRLF)
packet.Append( ' location.href=''/SlowReport'';'&CRLF)
packet.Append( ' } else {{'&CRLF)
packet.Append( ' if (intCount>20) {{'&CRLF)
packet.Append( ' clearInterval(reportTimer);'&CRLF)
packet.Append( ' reportTimer = setInterval(CheckReportProgress,10000);'&CRLF)
packet.Append( ' } else {{'&CRLF)
packet.Append( ' if (intCount>10) {{'&CRLF)
packet.Append( ' clearInterval(reportTimer);'&CRLF)
packet.Append( ' reportTimer = setInterval(CheckReportProgress,5000);'&CRLF)
packet.Append( ' }'&CRLF)
packet.Append( ' }'&CRLF)
packet.Append( ' } '&CRLF)
packet.Append( ' } '&CRLF)
packet.Append( ' });'&CRLF)
packet.Append( '};'&CRLF)
packet.Append( '$.get('''&CLIP(lURL)&CLIP(st.GetValue())&'&m=c&f=''+reportfn);'&CRLF)
packet.Append( '</script>'&CRLF)
DO SendPacket