473,508 Members | 3,688 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

STA object in Session and Thread Affiliation

Here's a question that I've not been able to get a definitive answer to.

Creating an STA object (such as a typical VB6 object) and assigning to the
ASP Session store is a bad thing.

It's a bad thing because it forces IIS to affiliate the Session with the
Thread on which the STA object is created.

This means all subsequent requests for that session can only be handled by
that worker thread and can therefore result it in poor performance as
requests queue up to access the thread they are affiliated with.

My question(s) is/are this:

Is this affilation now set in stone for the life time of the session?

Does removing the STA object from the session remove the affiliation or is
IIS/ASP just not that clever?

Thanks,

Anthony.
Feb 6 '06 #1
12 2195

"Anthony Jones" <An*@yadayadayada.com> wrote in message
news:e6**************@TK2MSFTNGP09.phx.gbl...
Here's a question that I've not been able to get a definitive answer to.

Creating an STA object (such as a typical VB6 object) and assigning to the
ASP Session store is a bad thing.

It's a bad thing because it forces IIS to affiliate the Session with the
Thread on which the STA object is created.

This means all subsequent requests for that session can only be handled by
that worker thread and can therefore result it in poor performance as
requests queue up to access the thread they are affiliated with.

My question(s) is/are this:

Is this affilation now set in stone for the life time of the session?
sure
Does removing the STA object from the session remove the affiliation or is
IIS/ASP just not that clever?
Sure.

ISP Session uses a workaround. But your VB class, needs to be persistable
(this is just a property). And persistance, needs to be implemented, so
within the VB6 class, you need to write the properties to a propertybag.
In the session, they will be written to a byte array and vice versa when
red.
Persistable objects like ADO recordsets as well, do not claim threads or RAM
(with ISP Session only) resources as soon as the session is persisted.
--
compatible web farm Session replacement for Asp and Asp.Net
http://www.nieropwebconsult.nl/asp_session_manager.htm
Thanks,

Anthony.


Feb 7 '06 #2
Thanks for the reply.

I don't use the session object to store state between requests.

What I was wondering is whether a page could place an object in the Session
object then server execute one or more other pages that could maniputlate
this object. Finally the original page would remove the object from Session
before completing it's response to the client.

Between requests Session contains nothing. However I very much suspected
that even this transistory assignment of an object to the Session would
irrevocably nail the Session to the work thread.

:( pity that it would be useful.

Cheers,

Anthony.
Feb 7 '06 #3

"Anthony Jones" <An*@yadayadayada.com> wrote in message
news:u8**************@TK2MSFTNGP15.phx.gbl...
Thanks for the reply.

I don't use the session object to store state between requests.

What I was wondering is whether a page could place an object in the
Session
object then server execute one or more other pages that could maniputlate
this object. Finally the original page would remove the object from
Session
before completing it's response to the client.

Between requests Session contains nothing. However I very much suspected
that even this transistory assignment of an object to the Session would
irrevocably nail the Session to the work thread.


Unless your object is marked as 'Both' and is free-threaded, that would not
happen.

And I suspect that Server.Execute does the following.
It detaches the current session
Attaches it to the target page,
executes that page,
detaches
reattaches the current page.

So basically, your system should not hang even if your object is marked as
'Apartment'.

After server.execute, remove your object

'for instance
Session.Contents.Remove "myobject"
Feb 7 '06 #4
>So basically, your system should not hang even if your object is marked as
'Apartment'.
Yes once a request has been handed over to a worker thread then any server
executes are performed by the same thread. I wasn't concerned that it might
hang.
After server.execute, remove your object 'for instance
Session.Contents.Remove "myobject"


Thats the key point. Does the line above remove the Sessions affiliation
with the thread.

Come to think of it when exactly does the affiliation get created?

1) When an STA object is first assigned into the Session object

OR

2) When a ASP processing of a request is finished and an STA object is found
to be in the Session object.

If the 2 then all is well because by then the object is gone (barring
errors, some work in a custom 500.100 page is probably warranted)

However I still suspect it is 1 and once in place stays put.

Anthony.
Feb 7 '06 #5

"Anthony Jones" <An*@yadayadayada.com> wrote in message
news:Oz**************@TK2MSFTNGP09.phx.gbl...
So basically, your system should not hang even if your object is marked
as
'Apartment'.
Yes once a request has been handed over to a worker thread then any server
executes are performed by the same thread. I wasn't concerned that it
might
hang.
After server.execute, remove your object

'for instance
Session.Contents.Remove "myobject"


Thats the key point. Does the line above remove the Sessions affiliation
with the thread.


It must be. We are not talking about .NET garbage collection, where the true
destroyment of an instance happens at any time (unless you use non-default
approaches)

If you destroy an object, IIS -will- anticipate on that. The object is
immediately gone including affiliation.

Anyway, imagine that I am wrong (unlikely here), still, the thread must
finish the current page until it would be released for another page request.

Are you having execution times of ASP pages above say, 5 seconds (per
request)?
Come to think of it when exactly does the affiliation get created?
I'm not -the- COM expert at this, but you should understand that 'apartment'
objects, in fact use a hidden window and each hidden window waits and
processes windows messages.
As long as the object is active, the thread is kidnapped for the object and
it won't be released by IIS for another user session.
1) When an STA object is first assigned into the Session object
true.
OR

2) When a ASP processing of a request is finished and an STA object is
found
to be in the Session object.
well, if a thread was assigned to a current asp page, that thread won't be
used for other pages as long as the page did not finish. It has no relation
with apartment affinity.
If you -leave- STA objects in the session, you'll have a problem.
If the 2 then all is well because by then the object is gone (barring
errors, some work in a custom 500.100 page is probably warranted)

However I still suspect it is 1 and once in place stays put.

Anthony.


Feb 8 '06 #6
>>>Session.Contents.Remove "myobject"

Thats the key point. Does the line above remove the Sessions affiliation
with the thread.
It must be. We are not talking about .NET garbage collection, where the truedestroyment of an instance happens at any time (unless you use non-default
approaches)


I guess I've just being a bit lazy.

Here is an experiment I've just run.

'VB6 ActiveX dll project "FindThread"
'Class Info
Public Property Get ThreadID() as Long
ThreadID = App.ThreadID
End Property

'Thread.asp
<%
Dim o
Set o = Server.CreateObject("FindThread.Info")
Response.Write o.ThreadID
%>

'Affiliate.asp
<%
Dim o
Set o = Server.CreateObject("MSXML2.DOMDocument.3.0")
Set Session.Contents.Item("test") = o

Session.Contents.Remove "test"
'Also tried:-
'Set Session.Contents.Item("test") = Nothing
'and:-
'Session.Contents.RemoveAll

%>

In browser:-

Visit Thread.asp and repeatedly press refresh.
Returned ID jumps about various threads.

Visit Affiliate.asp return to Thread.asp and continue pressing refreash
Returned ID remains the same ID.

From this is appears that a Session once affiliated remains affiliated
despite the fact that the Session no longer holds any references to STA
objects.

Tried it with the FreeThreaded DOM and the session remained unaffiliated.

Pity there isn't a Session.Unaffiliate method.

:(



Feb 8 '06 #7

"Anthony Jones" <An*@yadayadayada.com> wrote in message
news:uK**************@TK2MSFTNGP14.phx.gbl...
Session.Contents.Remove "myobject"

Thats the key point. Does the line above remove the Sessions
affiliation
with the thread.

It must be. We are not talking about .NET garbage collection, where the

true
destroyment of an instance happens at any time (unless you use non-default
approaches)


I guess I've just being a bit lazy.

Here is an experiment I've just run.

'VB6 ActiveX dll project "FindThread"
'Class Info
Public Property Get ThreadID() as Long
ThreadID = App.ThreadID
End Property

Pity there isn't a Session.Unaffiliate method.


Just curious. Does CreateObject("") instead of Server.CreateObject make a
difference?

Feb 8 '06 #8
>Just curious. Does CreateObject("") instead of Server.CreateObject make a
difference?


Nope same effect.

Feb 8 '06 #9

"Anthony Jones" <An*@yadayadayada.com> wrote in message
news:es**************@TK2MSFTNGP15.phx.gbl...
Just curious. Does CreateObject("") instead of Server.CreateObject make a
difference?


Nope same effect.


This must be because there is an option 'keep in memory' so the VBruntime is
not unloaded unless IIS 6 issues a special com function which unloads
unreferenced com objects.

Feb 9 '06 #10
>This must be because there is an option 'keep in memory' so the VBruntime
is
not unloaded unless IIS 6 issues a special com function which unloads
unreferenced com objects.


Where is this 'Keep in memory' option?

Are you talking about the VB 'Retain in memory' compile option?
This should always set for a DLL to be used in ASP.

I've never heared of an 'unreferenced com object', a com object that finds
it has no referrers will destroy itself.

Are you talking about to the mechanism where the exported function
DllCanUnloadNow is called and if true the DLL module is unloaded?

At this point though there are no COM instances of the Classes contained in
the DLL.

I don't think any of this standard COM behaviour has anything much to do
with the Sessions affiliation with a worker thread.

Feb 9 '06 #11

"Anthony Jones" <An*@yadayadayada.com> wrote in message
news:u0**************@TK2MSFTNGP09.phx.gbl...
This must be because there is an option 'keep in memory' so the VBruntime is
not unloaded unless IIS 6 issues a special com function which unloads
unreferenced com objects.


Where is this 'Keep in memory' option?

Are you talking about the VB 'Retain in memory' compile option?
This should always set for a DLL to be used in ASP.


sure
I've never heared of an 'unreferenced com object', a com object that finds
it has no referrers will destroy itself.
Are you talking about to the mechanism where the exported function
DllCanUnloadNow is called and if true the DLL module is unloaded?
sure.
At this point though there are no COM instances of the Classes contained
in
the DLL.

I don't think any of this standard COM behaviour has anything much to do
with the Sessions affiliation with a worker thread.


You don't think, I say "it might be".
The VBruntime is not documented that much and IIS not as well.
If you want, I can try to ask this to someone who might now.

Feb 11 '06 #12
>You don't think, I say "it might be".
The VBruntime is not documented that much and IIS not as well.
If you want, I can try to ask this to someone who might now.


I'm certain that this is an IIS/ASP specific behaviour.

I'm also convinced now after my own experimentations that once a session is
affiliated with a work thread that affiliation sticks and there's nothing an
ordinary ASP page can do about it.

It would be nice if an 'Inside IIS/ASP guru' would come along and say 'ah
yes it does but if you call the API function yadayada you can release the
affiliation' but I don't think that's likely to happen. :)

Thanks for your input it's enabled me to thrash through it and gave me the
motivation to get off my lazy backside and test it for myself.

Anthony.
Feb 11 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2008
by: Alex | last post by:
I'm having a problem porting an ASP solution to ASPX. In the ASP solution I'm accessing a DCOM server, create sub DCOM objects and call functions from VB script on the ASP pages. The DCOM object...
4
1824
by: Al Cohen | last post by:
We've got a few methods that take a long time to complete. We're in the process of starting to launch these as separate threads, and having the web form refresh every few seconds to report the...
8
1495
by: MattB | last post by:
Hello I am starting a new thread in a button click event. This thread calls an method which sends emails, I don't want the page to wait for the emails to finish going out as it slows the user...
2
2276
by: John Mullin | last post by:
We are having a problem which appears similar to a previous posting: http://groups.google.com/groups?hl=en&lr=&frame=right&th=d97f552e10f8c94c&seekm=OZw33z9EDHA.2312%40TK2MSFTNGP10.phx.gbl#link1 ...
2
2080
by: Gavin Lyons via .NET 247 | last post by:
Hello, I'm writing a newsletter application which uses backgroundthreading. I'm using Session variable to report on progresswhile it loops through a dataset. The 'Status.aspx' pagerefreshes every...
2
2107
by: Markus Prediger | last post by:
Hi NG, I have an asp.net project that uses an vb6 com object for some database-manipulation (I cannot rewrite it in .net, sorry, its not my decision). I want it to be instanciated seperately...
3
1654
by: ESmith | last post by:
I have multi-page form where I pass an object between pages as follows: On each page: // What page to go to next private void btnContinue_Click(object sender, System.EventArgs e) { if...
13
1733
by: | last post by:
Simple question, I think... I'm storing an object in the Session object. In the code behind I read that object: trx = CType(Session("Transaction"), BOCSTransaction) If I change any...
5
1989
by: jamie.jamazon | last post by:
I'm currently developing a small MVC framework using classic ASP (don't ask me why!) At it's core it calls the controller script which does the heavy logic and builds disconnected recordsets of the...
0
7128
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7332
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7058
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5635
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4715
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3191
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.