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]
-
mvp@spam.guard.caspershouse.com
"BravesCharm" <mastrauckas@gmail.com> wrote in message
news:1102452348.802310.102580@z14g2000cwz.googlegr oups.com...[color=blue]
> 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?
>[/color]