Link to home
Start Free TrialLog in
Avatar of ytgprasad
ytgprasad

asked on

how to spin off a dll thread into a call from asp

hi folks,
Can any one tell me how I can spinoff a dll method call into a backgroud thread.
Basically I am calling a method which is in dll from ASP PAGE, which is taking very long time. So I
want to spin that method call in bacground and return to user. Pls get back to me immediately.
Thank you,
Prasad
Avatar of martinv
martinv
Flag of Czechia image

VBScript (or ASP) does'nt support async call to dll. However Windows Scripting Host (WSH) could do it.

Put your dll calling code into VBS file and run it from ASP via WshShell.Run method.

WSH file:
...
 dim x
 set x = CreateObject("MyDll.MyObject")
 x.DoLongCall
 set x = Nothing
...

ASP file:
 ...
 ' construct command line - add necesary parameters
 dim strCmdLine = "path_to_wsh_file" & parameters
 ' execute it async
 dim WshShell
 set WshShell = Server.CreateObject("WScript.Shell")
 WshShell.Run (strCmdLine,0,false)


This will run strCmdLine in hidden windows and will not wait. You have to ensure, that this script will not be called too frequently - if everyone has access to it it could be used to DenialOfService type attack.

for more info see
http://msdn.microsoft.com/library/en-us/script56/html/wsmthrun.asp
Avatar of ytgprasad
ytgprasad

ASKER

hi marthinv,
I guess this solution is supported only in windows 98 and 2000. I am using NT 4.0
Thank you,
You could download WSH for Windows NT 4.0 at
http://msdn.microsoft.com/scripting/ (main page)

or
http://download.microsoft.com/download/winscript56/Install/5.6/W9XNT4Me/EN-US/scr56en.exe (direct link to NT4 download)
hi martinv,
Can u post one sample WSH file.
WSH Files are generaly the same as ASP files. Most notable exceptions are:

Instead of Response.Write you should use WScript.Echo
Instead of Server.CreateOBject you should use CreateObject
Server, Response, Request objects a not available.

1. script files could be run in two modes - in command line (outpout goes to stdout) and windows (output goes to dialog boxes). I recomend setting default mode to command line (must have if you want to run scripts from ASP pages). It could be done by entering following into command line:

CSCRIPT //W:cscript

2. sample script - it prints numbers from 1 to 10

--- file begins here --
dim i
for i = 1 to 10
  WScript.Echo "Number is: " & i
next
---- file ends here ---

save it to the file test.vbs. Vbs extensions tells WSH that file contains VBScript (and not JavaScript or Perl for example)

than run it either by entering
test.vbs
or
cscript test.vbs



hi martinv,
pls give an example of passing arguments from asp to vbs(WSH).
Thank you
ASKER CERTIFIED SOLUTION
Avatar of martinv
martinv
Flag of Czechia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial