While implementing an idea of web-based execution of Contributor Macros (see previous post), I’ve encountered the problem of some kind of progress-bar drawing in asp page.
When user hit’s asp page calling a Contributor Macro (which can take 15 min), he ought to see some action, telling him that “work is still going”. Mine idea was to draw sequential line of blue squares.
So the ASP page code will be like that:
set WScript = Server.CreateObject(“WScript.Shell”)
set oExec = WScript.exec(“c:\macro.bat”)
do while oExec.Status = 0
response.write(“<img src=’square.jpg’>”)
response.flush()
loop
That’s ok — but it draws a square every computer “tick”
Can fill up a page in 2 secs.
A Sleep(5 secs) is needed in cycle body, just before response.flush()
But there’s no sleep instruction in ASP. Workarounds are drastic.
* Create an inner cycle to slow up execution. 100% CPU load — very nice.
* Install a WaitFor dll. What, on every client site to use?
* Use an SQL to call Ms SQL Timeout function. Fantastic.
So we had to find another workaround for sleep. It quite fits in above mentioned list.
1 Create a sleep.vbs file with: “Wscript.Sleep 200000″ (a very big number of your choice) line. A script to sleep forever.
2 From ASP page run “cscript.exe /T:your_time_to_sleep sleep.vbs” . So it just stops sleep.vbs execution on timeout of your_time_to_sleep.
Final code looks like:
set WScript = Server.CreateObject(“WScript.Shell”)
set oExec = WScript.exec(“c:\macro.bat”)
do while oExec.Status = 0 response.write(“<img src=’square.jpg’>”)
Set WShell = Server.CreateObject(“WScript.Shell”)
Wshell.run(“cscript.exe /T:your_time_to_sleep sleep.vbs”) response.flush()
loop