473,378 Members | 1,387 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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
3 3209
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Elbert Lev | last post by:
Please correct me if I'm wrong. Python (as I understand) uses reference counting to determine when to delete the object. As soon as the object goes out of the scope it is deleted. Python does...
1
by: ash | last post by:
hi does anyone has any experience with flyweight pattern with refernce counting i want to share objects between multiple clients and want to delete the object from shared pool when the last...
27
by: Jason Heyes | last post by:
To my understanding, std::vector does not use reference counting to avoid the overhead of copying and initialisation. Where can I get a reference counted implementation of std::vector? Thanks.
0
by: Kalle Rutanen | last post by:
Hello I implemented reference counting in my program, and found out many problems associated with it. I wonder if the following problems can be solved automatically rather manually ? 1. ...
1
by: Tony Johansson | last post by:
Hello Experts! I reading a book called programming with design pattern revealed by Tomasz Muldner and here I read something that I don't understand completely. It says "A garbarage...
1
by: Tony Johansson | last post by:
Hello Experts! I reading a book called programming with design pattern revealed by Tomasz Muldner and here I read something that I don't understand completely. It says "A garbarage...
4
by: aaronfude | last post by:
Hi, Please consider the following class (it's not really my class, but it's a good example for my question): class Vector { int myN; double *myX; Vector(int n) : myN(n), myX(new double) { }...
1
by: oec.deepak | last post by:
Hi Cn any one telll me what is Reference counting in C++.
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.