how to initialise an object to be available for all users? ASP.net

A

Annie

hello all,

is it possible at all?

i have a class that encapsulates a Hashtable collection. What i want is to
initialise this object once and only once and
then be able to access its Public Static methods always.

What i want is when the user logs in i gets its detail and add him/her in
the hashtable until her/she is online and similarly
for next user and so on until they log out or close the browser then i
remove them from hash table.

I don't know how to inititialize the object once?
Is it possible at all?

TA
 
B

bouagja

You can initialize the object in the Application_OnStart event and add
it to the application object, and then in the Session_OnStart event add
the user information to the object.
 
G

Guest

1. Use a singleton pattern for the object that encapsulates the Hashtable (or
place it in Application).

public class SingletonHashtable : Hashtable
{
//Cannot instantiate object with constructor
private SingletonHashtable
{
}

//single static hashtable
private static SingletonHashtable a;

public SingletonHashtable GetHashtable()
{
if(a==null)
a = new Hashtable();

return a;
}
}

2. Add users on Session_Start and get rid of them on Session_End.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
A

Annie

Hello Cowby,

Thanks for your reply however I don't think the code you have written will
work though it compiles ...

This line

private static SingletonHashtable a;
and the line:
a = new Hashtable();
are not good i believe?

variable type is as SingletonHashtable while creating new instance of
Hashtable.

It never checks for the null value if(a==null)?? that is what I had the
problem with ...

TA
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top