Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > how to initialise an object to be available for all users? ASP.net

Reply
Thread Tools

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

 
 
Annie
Guest
Posts: n/a
 
      09-12-2005
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


 
Reply With Quote
 
 
 
 
bouagja@gmail.com
Guest
Posts: n/a
 
      09-12-2005
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


 
Reply With Quote
 
 
 
 
=?Utf-8?B?Q293Ym95IChHcmVnb3J5IEEuIEJlYW1lcikgLSBNVlA=?=
Guest
Posts: n/a
 
      09-12-2005
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
>
>
>

 
Reply With Quote
 
Annie
Guest
Posts: n/a
 
      09-13-2005
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" <(E-Mail Removed)> wrote in message
news:43258f09$(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Want to initialise text box on basis of... zoneal@yahoo.com ASP .Net 1 10-19-2005 07:35 PM
cannot initialise variable in try block? Nandan Java 4 04-29-2005 07:22 AM
how to initialise a reference in g++ Arik Funke C++ 14 10-27-2004 04:39 PM
How can I initialise values in a process??? MNQ VHDL 4 06-17-2004 04:53 PM
Alternate way to initialise static object. Yu C++ 12 07-10-2003 04:47 AM



Advertisments