467,134 Members | 1,044 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,134 developers. It's quick & easy.

Trouble with reference counting

BravesCharm Dec 7, 10:57 am show options

Newsgroups: microsoft.public.dotnet.distributed_apps
From: "BravesCharm" <mastrauc...@gmail.com>
Date: 7 Dec 2004 10:57:40 -0800
Local: Tues, Dec 7 2004 10:57 am
Subject: Have trouble with reference counts!
Reply | Reply to Author | Forward | Print | Individual Message | Show
original | Remove | Report Abuse

I'm developing a website in .NET. Now every user that logs into the
website registers a token with a Token Manger by MSMQ. The Token
Manager is a Windows Service that stores all tokens to keep a count of
how many times a particular token is registered on the system (other
parts of the system that has nothing to do with the website can also
communicate with the Token manager and registers that token with the
Token Manger). When the user logs out, it un-registers that token with
the Token manager, and if the Token Manager Ref count is at zero (No
other part of the system is using the token), it deletes that token.
Now where my problem comes in with Sessions in ASP.NET and State Server
and how .NET does Serialization. When a customer logs in, it registers
the token and stores it into a class that has a dispose pattern as well
as a finalizer. When ASP.NET switches the class between State Server
and IIS it gets Serialized/Desterilized. When it gets Desterilized it
will create a new instance of the class and store it into the Session
variables. Now when the page is done executing, it will call the
finalizer for that class which un-registers the token with the Token
manager which screws everything up! So what I needed was a way to have
some way of keeping a reference count between processes so I know when
to release the token. I thought the best way to do this was by using
Semaphores. The only problem, you cannot query the current count of a
semaphore without calling ReleaseSemaphore, so i'm not really able to
get the reference count with Semaphores. I found NtQuerySemaphore but
for some reason it always returns 1 and no the actural count.
So may question is, can anyone tell me the best way to keep the
reference count between processes?

Nov 16 '05 #1
  • viewed: 2904
Share:
3 Replies
BravesCharm,

The object that registers and unregisters the token shouldn't be doing
this. Rather, I would just hook into the Session start and end events
(provided through the global class) and register unregister the token there.
This will allow you to retain your custom information on the object, without
having to worry about registration.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"BravesCharm" <ma*********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
BravesCharm Dec 7, 10:57 am show options

Newsgroups: microsoft.public.dotnet.distributed_apps
From: "BravesCharm" <mastrauc...@gmail.com>
Date: 7 Dec 2004 10:57:40 -0800
Local: Tues, Dec 7 2004 10:57 am
Subject: Have trouble with reference counts!
Reply | Reply to Author | Forward | Print | Individual Message | Show
original | Remove | Report Abuse

I'm developing a website in .NET. Now every user that logs into the
website registers a token with a Token Manger by MSMQ. The Token
Manager is a Windows Service that stores all tokens to keep a count of
how many times a particular token is registered on the system (other
parts of the system that has nothing to do with the website can also
communicate with the Token manager and registers that token with the
Token Manger). When the user logs out, it un-registers that token with
the Token manager, and if the Token Manager Ref count is at zero (No
other part of the system is using the token), it deletes that token.
Now where my problem comes in with Sessions in ASP.NET and State Server
and how .NET does Serialization. When a customer logs in, it registers
the token and stores it into a class that has a dispose pattern as well
as a finalizer. When ASP.NET switches the class between State Server
and IIS it gets Serialized/Desterilized. When it gets Desterilized it
will create a new instance of the class and store it into the Session
variables. Now when the page is done executing, it will call the
finalizer for that class which un-registers the token with the Token
manager which screws everything up! So what I needed was a way to have
some way of keeping a reference count between processes so I know when
to release the token. I thought the best way to do this was by using
Semaphores. The only problem, you cannot query the current count of a
semaphore without calling ReleaseSemaphore, so i'm not really able to
get the reference count with Semaphores. I found NtQuerySemaphore but
for some reason it always returns 1 and no the actural count.
So may question is, can anyone tell me the best way to keep the
reference count between processes?

Nov 16 '05 #2
If you are using Session Server is Session start and end reliable?

Nov 16 '05 #3
Nicholas Paldino,
This will not work because Session_End is only supported in InProc
mode. I will not be able to unregister the token because the event
would never gets called.

Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Elbert Lev | last post: by
1 post views Thread by ash | last post: by
reply views Thread by Kalle Rutanen | last post: by
1 post views Thread by Tony Johansson | last post: by
1 post views Thread by Tony Johansson | last post: by
4 posts views Thread by aaronfude@gmail.com | last post: by
1 post views Thread by oec.deepak@gmail.com | last post: by
275 posts views Thread by Astley Le Jasper | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.