We help IT Professionals succeed at work.

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

ytgprasad
ytgprasad asked
on
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
Comment
Watch Question

Commented:
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

Author

Commented:
hi marthinv,
I guess this solution is supported only in windows 98 and 2000. I am using NT 4.0
Thank you,

Commented:
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)

Author

Commented:
hi martinv,
Can u post one sample WSH file.

Commented:
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



Author

Commented:
hi martinv,
pls give an example of passing arguments from asp to vbs(WSH).
Thank you
Commented:
I don't have to write all your code for 200 points :-)

But anyway:

-------- test.asp -------------
<%
dim strCmdLine
strCmdLine = "c:\webtest\test.vbs parm1 parm2 parm3"
' execute it async
dim WshShell
set WshShell = Server.CreateObject("WScript.Shell")
WshShell.Run strCmdLine,0,false
%>



--------- test.vbs-----------
' list all arguments
Set objArgs = WScript.Arguments
For I = 0 to objArgs.Count - 1
   WScript.Echo "Argument " & i & ": " & objArgs(I)
Next

' print first argument value
wscript.echo WScript.Arguments(0)
--------------------------------

note that you will not see any output when called from ASP files. Change WScript.Echo in test.vbs to log fiel write or whatever you want. Make sure, that IUSR_xxx has execute access to the directory, where test.vbs is located.
Valliappan ANSenior Tech Consultant
CERTIFIED EXPERT

Commented:
<ping>

Explore More ContentExplore courses, solutions, and other research materials related to this topic.