I use static variables in my asp.net apps instead of application variables
to store global parameters, its worked well for me so far but I was
wondering if it is efficient. Does anyone know how static variables are
handled in asp.net?
--
Frank Wisniewski MCSE 4.0, MCP+I, A+
f p w 2 3 @ h o t m a i l . c o m 5 2515
Hi Frank:
If the static variables are readonly, then they can be much friendlier
than using the Application collection. For one, you don't have the
overhead of locking that the Application collection does for you, and
secondly they are type safe and you don't have to do any casting or
worry about boxing.
If you need to read and write to static variables take care, because
ASP.NET is a multithreaded environment. The Application collection
does locking for you during a Get or a Set with a reader / writer
lock, but using statics you are on your own.
--
Scott http://www.OdeToCode.com
On Thu, 9 Sep 2004 12:57:50 -0500, "Frank Wisniewski"
<fp***@hotmail.com> wrote: I use static variables in my asp.net apps instead of application variables to store global parameters, its worked well for me so far but I was wondering if it is efficient. Does anyone know how static variables are handled in asp.net?
How do you use static variables?
Is that like global variables that are always available?
-Frank
"Frank Wisniewski" <fp***@hotmail.com> wrote in message
news:41********@Usenet.com... I use static variables in my asp.net apps instead of application variables to store global parameters, its worked well for me so far but I was wondering if it is efficient. Does anyone know how static variables are handled in asp.net?
-- Frank Wisniewski MCSE 4.0, MCP+I, A+ f p w 2 3 @ h o t m a i l . c o m
I agree with everything Scott said.
If you are after readonly values, you should also consider using a
configuration file, namely the web.config with your own configuration
section ( http://www.openmymind.net/Configuration/index.html). Its good
practice to closely examine hard-coded to see if they should be, well
hard-coded.
As Scott said, you can run into nasty stuff if you are reading and writing
to and from them. If this is the case, i would definitely avoid static
variables...I would also avoid the Application object, and use a database
with Caching (I hate the application object ;) )
Karl
--
MY ASP.Net tutorials http://www.openmymind.net/
"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:rr********************************@4ax.com... Hi Frank:
If the static variables are readonly, then they can be much friendlier than using the Application collection. For one, you don't have the overhead of locking that the Application collection does for you, and secondly they are type safe and you don't have to do any casting or worry about boxing.
If you need to read and write to static variables take care, because ASP.NET is a multithreaded environment. The Application collection does locking for you during a Get or a Set with a reader / writer lock, but using statics you are on your own.
-- Scott http://www.OdeToCode.com
On Thu, 9 Sep 2004 12:57:50 -0500, "Frank Wisniewski" <fp***@hotmail.com> wrote:
I use static variables in my asp.net apps instead of application
variablesto store global parameters, its worked well for me so far but I was wondering if it is efficient. Does anyone know how static variables are handled in asp.net?
Hi Frank:
If I have this class in an ASP.NET project:
public class Foo
{
public static string Bar
{
get
{
// pull a string from the config file,
// the database, a resource file, etc..
}
}
}
Then I can write:
Foo.Bar
from anywhere else in code to pull back the string I need. Public
static members are global and always available (which can make them a
double edged sword in some scenarios).
VB.NET works the same way, except the keyword is "Shared" instead of
static.
--
Scott http://www.OdeToCode.com
On Thu, 9 Sep 2004 14:14:10 -0400, "Frank Mamone"
<fr**********@canada.com> wrote: How do you use static variables?
Is that like global variables that are always available?
-Frank
Thanks!
"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:1a********************************@4ax.com... Hi Frank:
If I have this class in an ASP.NET project:
public class Foo { public static string Bar { get { // pull a string from the config file, // the database, a resource file, etc.. } } }
Then I can write:
Foo.Bar
from anywhere else in code to pull back the string I need. Public static members are global and always available (which can make them a double edged sword in some scenarios).
VB.NET works the same way, except the keyword is "Shared" instead of static.
-- Scott http://www.OdeToCode.com
On Thu, 9 Sep 2004 14:14:10 -0400, "Frank Mamone" <fr**********@canada.com> wrote:
How do you use static variables?
Is that like global variables that are always available?
-Frank
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: jacob navia |
last post by:
As far as I understood the standard, non-automatic variables
(static/global data) can't be cached in registers because in a
multiprocessing or multi-threading environment, another
thread/processor...
|
by: AnandRaj |
last post by:
Hi guys,
I have a few doubts in C.
1. Why static declartions are not allowed inside structs?
eg
struct a {
static int i;
};
Throws an error ..
|
by: Vishwanathan Raman |
last post by:
Hi
I have a declared a static DataSet object SOBJ in Global.asax.I also have a
localy defined DataSet LSOBJ in Global.asax which I am storing in Application
State.Is there any technical...
|
by: Dennis |
last post by:
I have a function which is called from a loop many times. In that function,
I use three variables as counters and for other purposes. I can either use
DIM for declaring the variables or Static. ...
|
by: Vladislav Kosev |
last post by:
I have this strange problem now twice: I am writing this relatevely large web
site on 2.0 and I made a static class, which I use for url encoding and
deconding (for remapping purposes). This static...
|
by: Stephen Walch |
last post by:
Our application environment consists of three basic layers:
1. Third-party unmanaged DLLs that were written before the CLR was invented
and maintain a significant amount of information (including...
|
by: CDMAPoster |
last post by:
About a year ago there was a thread about the use of global variables
in A97:
http://groups.google.com/group/comp.databases.ms-access/browse_frm/thread/fedc837a5aeb6157
Best Practices by Kang...
|
by: Zytan |
last post by:
I see that static is more restricted in C# than in C++. It appears
usable only on classes and methods, and data members, but cannot be
created within a method itself. Surely this is possible in...
|
by: Rahul |
last post by:
Hi Everyone,
It is known that static member variables can be accessed without
creating an instance of the class and it serves as a global variable
without polluting the global name space.
So...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
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...
|
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: 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,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |