By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,282 Members | 1,526 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,282 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Nov 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.

--
Ahmed Bouagja

Annie wrote:
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


Nov 19 '05 #2

P: n/a
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!
***************************
"Annie" wrote:
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

Nov 19 '05 #3

P: n/a
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

"Annie" <my**************@gmail.com> wrote in message
news:43********@dnews.tpgi.com.au...
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

Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.