Advanced COM Activate method
Activate  method

Starts (activates) the thread maintained by the object. Until the method is called the internal thread is not started. After starting the thread it initializes and waits for Execute requests.




Set thread = Server.CreateObject("newObjects.utilctls.COMThread")
thread.Execute someobject,"somemethod"

Creates a COM thread, activates it and requests execution of some method on some object. And more detailed version.

Set ap = Server.CreateObject("newObjects.utilctls.COMApartment")
Set obj = ap.CreateObject("Some_Object_ID")
Set thread = Server.CreateObject("newObjects.utilctls.COMThread")
thread.Execute obj,"somemethod"

How to execute another script? Here is a simple example. You will need to preserve object references to the script host, thread and the apartment somewhere outside the current ASP page - the best place is Application (see also the sample in the COMApartment overview). 

' Create an apartment
Set ap = Server.CreateObject("newObjects.utilctls.COMApartment")

' Create a script host in it
Set host = ap.Creator.CreateObject("newObjects.Scphost.ScpMan2")

' Open the script from a file
Set sf = Server.CreateObject("newObjects.utilctls.SFMain")
Set file = sf.OpenFile(Server.MapPath("thread.js"),&H40)

' Set idle priority to the task
ap.Priority = -15

' Initialize a script interpreter 
b = host.LoadEngine("JScript")
If Not b Then Response.Write "FAILED to load the engine<BR>"

' Read the script from the file and add it into the host
b = host.AddText(file.ReadText(-2))
If Not b Then Response.Write "FAILED to load the script<BR>"

' Give the script a reference to an object accessible for 
' the ASP pages as well 
host.Add "State", Application

' Create the thread
Set thread = Server.CreateObject("newObjects.utilctls.COMThread")

' Preserve the objects involved in the Application
Set Application("Host") = host
Set Application("Ap") = ap
Set Application("Thread") = thread

' Activate the thread and then execute the script by calling the 
' script host's Run method
thread.Execute host, "Run"
Response.Write "Thread started<BR>"
Response.Write "Thread busy indication: " & thread.Busy & "<BR>"


See also the COMApartment and COMThread notes

Applies to: COMthread object

newObjects Copyright 2001-2006 newObjects [ ]