473,799 Members | 2,665 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Add a Hashtable to Applicatoin to save Global data

Is that a good idea to add a Hashtable to System.Windows. Forms.Applicati on
class? And we can put any user global data in it.

I have some class library used by a few other applications in slight
different way. This way (and ocz there are other ways) I don't have to user
different parameter to call a method or invent an other global data
repository.

Regards,
~.~.~.~.~.~.~.~ .~.~.~.~.~.~.~. ~.~.~.~.

Ryan Liu
Shanghai Fengpu Software Co. Ltd
Shanghai , China

http://www.PowerCATI.com Powerful CATI!
http://www.fpsoft.net.cn
~.~.~.~.~.~.~.~ .~.~.~.~.~.~.~. ~.~.~.~.

Dec 30 '07 #1
8 1847
On Sun, 30 Dec 2007 00:09:59 -0800, Ryan Liu <rl**@PowerCATI .comwrote:
Is that a good idea to add a Hashtable to
System.Windows. Forms.Applicati on class? And we can put any user global
data in it.

I have some class library used by a few other applications in slight
different way. This way (and ocz there are other ways) I don't have to
user different parameter to call a method or invent an other global data
repository.
What's wrong with just making a static class for your global data? Or a
static member of some more-relevant class? (Stored in a Hashtable, or
whatever other container you find appropriate, of course).

I mean, I suppose you could use extension to add something to the
Application class, but I'm not sure what the point would be. What's so
tempting about the Application class that you want to put your data there
rather than something more specific to your own code?

Pete
Dec 30 '07 #2
On Sun, 30 Dec 2007 00:32:01 -0800, Peter Duniho
<Np*********@nn owslpianmk.comw rote:
[...]
I mean, I suppose you could use extension to add something to the
Application class [...]
Actually, strike that. I overlooked that you can only add an extension
method as an instance method, and with no way to get an instance of the
Application class, you can't extend it even via extension methods.

So you're out of luck anyway. The Application class is sealed and there's
no way for you to add new data members to it anyway, rendering the
question moot.

Pete
Dec 30 '07 #3

"Peter Duniho" <Np*********@nn owslpianmk.comå †™å…¥æ¶ˆæ¯
news:op******** *******@petes-computer.local. ..
On Sun, 30 Dec 2007 00:32:01 -0800, Peter Duniho
<Np*********@nn owslpianmk.comw rote:
>[...]
I mean, I suppose you could use extension to add something to the
Application class [...]

Actually, strike that. I overlooked that you can only add an extension
method as an instance method, and with no way to get an instance of the
Application class, you can't extend it even via extension methods.

So you're out of luck anyway. The Application class is sealed and there's
no way for you to add new data members to it anyway, rendering the
question moot.

Pete

Peter,

After the post, I find the System.Enviorme nt class is for this purpose. But
it's key and value is only string type. Now I do come out with my own static
class which use Hashtable internally.

Regards,
Ryan

Dec 30 '07 #4
After the post, I find the System.Enviorme nt class is for this purpose.
I realise you aren't using this, but for completeness, I suspect that
this is intended for environment variables
Now I do come out with my own static class which use Hashtable internally.
Nobody will stop you; but it doesn't seem very elegant; you will have
no assistance to help you know the expected keys or types for
settings. I'm not sure this is buying you much... personally I'd be
more inclined to have a usage-specific class with typed, named
properties (quite probably static).

A final thought; watch out for thread safety and object lifetime
(objects held globally won't be garbage collected, nor will anything
they can see [think "events"]).

Marc
Dec 30 '07 #5
After the post, I find the System.Enviorme nt class is for this purpose.
>
I realise you aren't using this, but for completeness, I suspect that
this is intended for environment variables
as in what u see when u type "set" in a command prompt...

hmm...

this could get really complicated... a max len of env var at 255? no,
path can be longer now... but still... would not build hastables
there ;)

and yes, all strings, like WriteLine(Envir onment.CurrentD irectory);
will tell u where the os thinks u are...

//CY
Dec 30 '07 #6
and yes, all strings, like WriteLine(Envir onment.CurrentD irectory);

oh, forgot the point of that.. take 2 programs (same prog) start in
differrent dir and they will tell u different directorys.. I dont
think its shacer or common, initalized by system defaults but can be
set by process

//CY
Dec 30 '07 #7
Yes; my point being - I wouldn't go near this for internal application
data (which is what you are talking about).

Marc
Dec 30 '07 #8

----- Original Message -----
From: "Marc Gravell" <ma**********@g mail.com>
Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
Sent: Sunday, December 30, 2007 6:54 PM
Subject: Re: Add a Hashtable to Applicatoin to save Global data

>After the post, I find the System.Enviorme nt class is for this purpose.
I realise you aren't using this, but for completeness, I suspect that
this is intended for environment variables
>Now I do come out with my own static class which use Hashtable
internally.
Nobody will stop you; but it doesn't seem very elegant; you will have
no assistance to help you know the expected keys or types for
settings.
Oh, I come out another enum for keys.
I'm not sure this is buying you much... personally I'd be
more inclined to have a usage-specific class with typed, named
properties (quite probably static).
I try to write a generic class to set/get applicaton level variables. (this
class itself does not bind to the enum I mentioned above). By doing this, I
think I can avoid writing more and more classes or adding more and more
properties. And worse when some properties get oboslated.

Ryan

A final thought; watch out for thread safety and object lifetime
(objects held globally won't be garbage collected, nor will anything
they can see [think "events"]).

Marc
Dec 30 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3985
by: Cederstrom | last post by:
Hello group! :) I want to create a config/status object, that will contain a Hashtable. This object I would like to save through Serialization, but im having some trouble. My hashtable contain some objects, from a class I created myself. I read that I need to make my own "add" method, which I hopefully did correct. I hope someone can spot my wrongdoings, and point me in the right direction. The code is in the bottom of this post:
1
8717
by: francois | last post by:
Hi, I have a webservice that I am using and I would like it to return an XML serialized version of an object. the class of the object is defined serializable as the following: public class Event {
5
2833
by: francois | last post by:
First of all I would to to apologize for resending this post again but I feel like my last post as been spoiled Here I go for my problem: Hi, I have a webservice that I am using and I would like it to return an XML serialized version of an object.
9
4040
by: Oberon | last post by:
My HashTable (Global.Games) is a static collection of objects of type Game. A Game object has 8 fields (exposed as properties). The key to the HashTable is also one of these fields (GameID, of type int). When I try to create a SortedList from the HashTable with the following: SortedList sortedGames = new SortedList(Global.Games); I get an error message:
11
2772
by: Crirus | last post by:
Easyest and fastest way... :) -- Ceers, Crirus ------------------------------ If work were a good thing, the boss would take it all from you ------------------------------
5
2692
by: Dick | last post by:
Hello, I'm trying to serialize a class with a Hashtable within: ' Class code: Imports System.Collections Class clsOptions Public countID As Integer Public persons As New Hashtable End Class
7
2554
by: SevDer | last post by:
Hi We have a static hashtable that is located in another tier in our n-tiered web application. And we are storing big but not huge objects in this hashtable and the key to the objects is through Session.SessionID. public class DataStore : System.Web.UI.Page { public static Hashtable ht = new Hashtable();
8
3725
by: chrisben | last post by:
Hi, If I am not sure how many items will be in my Hashtable/ArrayList dynamically (multiple threads can add/remove/check the item), however, I can estimate the total number will not exceed 60000. How much can I gain in term of performance if I decalre the hash as Hashtable h = new Hashtable(60000); instead of
6
3579
by: stoogots2 | last post by:
am using Visual Studio 2003, .Net Framework 1.1, C#. I get a SystemNullReferenceException when trying to do a hashtable.add(string,string) from a login page, and I do not understand why because all of the other data items from the Global.asax.cs are accessible in my pages. The key and value are not null (according to the watch window), so it is something else. This is likely something retarded, so I apologize in advance. It is my first...
0
9689
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10495
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10269
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10032
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5469
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2942
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.