Okay, first, the Application Collection is there for backwards
compatibility, so you shouldn't be using it, as it isn't thread-safe. You
should be using the Application Cache instead. The Cache is thread-safe, and
objects stored there can be expired according to whatever rules you specify.
Second, forget the rules for ASP. EVERYTHING in .Net is an object, so store
anything you want in the Cache (except for database Connections, which
should be destroyed ASAP).
Third, to reference the Application Cache, you would have to refer to it in
context. For example, if you are writing code inside a Page class
definition, you can refer to "Cache" directly, as the Application Cache is
the "Cache" property of the Page class. If you're writing a utility class of
some sort, you need to grab the Cache from the current HttpContext, as in:
HttpContext.Current.Cache.
Finally, it might be best to forget about Modules. Although you can
certainly build Modules in .Net, they are also more for backwards
compatibility. A Module is basically a collection of Shared (static) data
and Methods, not very object-oriented. Instead, try to get used to
developing Classes and Class Libraries. You can create static (Shared)
properties and methods within a Class, but you will more often be working
with instantiated Classes. Shared/static methods and properties are more
problematic, and less likely to be necessary than instantiated Classes. A
Shared/static property is, in a sense, global, in that it is globally
accessible, but you don't have the control over accessibility that you have
with an instantiated Class property. For example, if a property is a public
property of an instantiated Class, you can have more than one instance of
it, whereas a static/Shared property exists in one and only one place. You
might say that a shared property of a module has Application scope, but it
is not the same thing as storing an object in the Application or Application
Cache. It actually exists in the heap, and, again, in one and only one
place.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.
"Keith Chadwick" <> wrote in message
news:...
I am having some trouble referencing an Application("myVar") variable from
within a module.vb file on my ASP.NET site.
According to the documentation I should be able to reference
System.Web.HttpApplication but it does not seem to like that one bit.
I also have a MSXML2.DOMDocument30 defined as a public object within the vb
module which is loaded during the application start up with a bunch of XML.
What is weird is that the data contained within the XML object seems to
remain as an application level even though it is not defined as an
application variable. The xml is stored within an application("myxml")
variable but the object is not defined as an application level variable. In
the old ASP module we where not supposed to declare objects within an
Application variable so I am not in .NET.
I am coming from the old ASP module so I know I am thinking far to linear at
this point but am I to understand that an object/var declared as public
within a module.vb means its scope is application? If so, huh!
Thanks in advance
Keith