473,395 Members | 2,468 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,395 software developers and data experts.

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

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

Similar topics

15
by: Scott Auge | last post by:
I am looking for comments on something that lets me abstract database updates in an object. Lemme explain what I am thinking: Lets say I have an object Person with... SetFirstName()...
12
by: Yu | last post by:
I have found that the static object is initialised at the time when the shared libary is loaded. The initialisation caused the invocation of the constructor. May I know of any way that I can...
0
by: Craig Rodrigues | last post by:
REQUEST FOR DISCUSSION (RFD) unmoderated group comp.object.corba.tao This is a formal Request For Discussion (RFD) to create comp.object.corba.tao as an unmoderated world-wide Usenet newsgroup...
5
by: LL | last post by:
Hi, Where is the best place to check the session's object, if it's null, then redirect the user to login page? put into every page's load event? Thanks.
6
by: Graham Pengelly | last post by:
Hi I'll try to spell out my problem as succinctly as possible... My database has a User table, an Organisation table, a Department table and a JobType table (amongst others) The...
2
by: Tomás | last post by:
Up until lately I've been writing all mad kinds of code for accomplishing things, but lately I've decided to lean more toward the whole readability, etc. side of things. I have a command line...
14
by: Frederick Gotham | last post by:
How do we initialise an aggregate member object of a class? The following won't compile for me: struct MyStruct { int i; double d; }; class MyClass { private:
3
FishVal
by: FishVal | last post by:
Windows Script Host Object library. Full name: Windows Script Host Object Model LibName: IWshRuntimeScripting Location: ...\WINDOWS\system32\wshom.ocx The present tip is closely related to...
2
dream party
by: dream party | last post by:
Inserting a Flash (SWF, FLV) file into HTML web page is already an old and familiar thing to all of us. It is a rather non-flexible thing that just to edit some options in the template. However, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.