Why does a class created in global.asa Application_Start get removed right away?

G

Grant Schenck

Hello,

I posted an this issue before but I'm clearer on what is going on.

I have a simple web site with a global.asa and a single .asp file.

In global.asa I handle both Application_OnStart and Application_OnEnd (see
below.)

The ShoreTelMakeCallTransfer object is a simple VB test object which
currently just logs class_initialize and class_terminate along with
OnStartPage and OnEndPage.

When I acess my ASP page, I see the folowing output from my logging:

--> Class_Initialize
<-- Class_Initialize

--> OnStartPage
<-- OnStartPage

--> OnEndPage
<-- OnEndPage

--> Class_Terminate
<-- Class_Termiante

What I don't understand is why Class_Terminate is called?

Based on the fact that in Application_OnStart I:

set Application("ShoreTelMakeCallTransfer") = ShoreTelMakeCallTransfer

Shouldn't that cause the object to stay loaded????

Thanks, Grant Schenck

-------------------------------------------------------
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Option Explicit

Sub Application_OnStart
On Error Resume Next
Dim ShoreTelMakeCallTransfer
Application("ShoreTelMakeCallTransfer") = NULL
set ShoreTelMakeCallTransfer =
Server.CreateObject("STMakeCallTransfer.STObject")
set Application("ShoreTelMakeCallTransfer") = ShoreTelMakeCallTransfer
End Sub

Sub Application_OnEnd
On Error Resume Next
Dim ShoreTelMakeCallTransfer
set ShoreTelMakeCallTransfer = Application("ShoreTelMakeCallTransfer")
set Application("ShoreTelMakeCallTransfer") = NULL
Application.Contents.Remove("ShoreTelMakeCallTransfer")
End Sub

</SCRIPT>
 
G

Grant Schenck

Of course as soon as I typed this I think I found the problem...

Specifically, because of my "On Error Resume Next" I was masking the
problem. Commenting those out give me:

-----------------------------------
Application object error 'ASP 0197 : 80004005'
Disallowed object use
/LM/W3SVC/1/Root/MyASP/global.asa, line 31
Cannot add object with apartment model behavior to the application intrinsic
object.
-----------------------------------

So, is this a drop dead issue? Is using STA type VB object not supported?

If so, can I use VB at all or must I use C++ and build an MTA?

Thanks, Grant Schenck
 
G

Grant Schenck

See my response to my own email.

It looks like you simply can NOT store an STA (VB) COM object in the
application.

It sounds like older versions of IIS did allow this. This seems like a
bogus limitation becasue at least in my case, the object methods are all
VERY fast and don't block the calling thread in any significant way.

So, does anyone have any reason to believe that this isn't true or if there
is anykind of workaround?

Thanks, Grant Schenck
 
M

Mark Schupp

If I understand the threading issues the problem is that you would end up
tying every page containing the STA object to a single thread. IIRC you
could put some STA objects in Application scope in IIS4 but it was a bug not
a "feature".

You might be able to fool IIS into thinking your object was FreeThreaded by
changing the registry but you would be risking crashes if two threads tried
to access any global data at the same time.

Again, what are you trying to accomplish with your object? There may be
alternative methods available.
 
G

Grant Schenck

At this point I'll play by the rules and write an C++ based MTA. Internally
it will be using an STA but that should be OK... I believe...

Also, while were on the subject, the STA uses a windows timer. Do you know
if ASP->MTA->STA will allow a message pump be available to the STA?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top