Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > global class (simple question!)

Reply
Thread Tools

global class (simple question!)

 
 
=?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=
Guest
Posts: n/a
 
      08-12-2007
Hi,

There are many tutorials out there, ie:
http://samples.gotdotnet.com/quickst...eoverview.aspx
Google is your friend

Regards
--
Milosz


"ma" wrote:

> Thanks,
> Where can I read more about application instance or caching? Any good
> tutorial on the web?
>
> Regards
>
> "Milosz Skalecki [MCAD]" <> wrote in message
> news:0094AF4C-AE9D-4AAC-BF47-...
> > Hi there,
> >
> > Usually, when the class cannot be static and you require one global
> > instance
> > of a class, singleton pattern should be used (this is thread safe
> > variant):
> >
> >
> > public class Global
> > {
> > private Global()
> > {
> > }
> >
> > private static object sync = new object();
> > private static Global instance = null;
> >
> > public Global Instance
> > {
> > get
> > {
> > lock(sync)
> > {
> > if (instance == null)
> > {
> > instance = new Global();
> > }
> > }
> > return instance;
> > }
> > }
> > }
> >
> > // usage
> > Global global = Global.Instance;
> >
> > In addition, in ASP.NET there's build-in mechanism for such scenarios
> > called
> > Application state (instance can be initialized in the Global.asax
> > Application_Start event) or Caching (you'd have to make sure race
> > condition
> > is eliminated).
> >
> > HTH
> > --
> > Milosz
> >
> >
> > "ma" wrote:
> >
> >> Thanks.
> >> Is there any other way to instantiate an object with application scope?
> >> Regards
> >>
> >>
> >>
> >> "John Mott" <> wrote in message
> >> news:...
> >> >
> >> > "ma" <> wrote in message
> >> > news:...
> >> >> Thanks John, But it doesn't work!
> >> >>
> >> >> I did this in the page load event:
> >> >>
> >> >> protected void Page_Load(object sender, EventArgs e)
> >> >>
> >> >> {
> >> >>
> >> >> Global GlobalInstance=new Global();
> >> >>
> >> >> Response.Write(GlobalInstance.myclass.mystring);
> >> >>
> >> >> GlobalInstance.myclass.mystring = "new string";
> >> >>
> >> >> }
> >> >>
> >> >>
> >> >>
> >> >> so the first time that I load this page, it should show "Hello World"
> >> >> and
> >> >> the next time that I download the page ( or refresh it) it should show
> >> >> "new string" but it always show "hello world"
> >> >>
> >> >> Any suggestion?
> >> >>
> >> >> Regards
> >> >>
> >> >
> >> > Make the Global class itself static, like this
> >> >
> >> > public static class Global {
> >> > public static string myString = "default";
> >> > }
> >> >
> >> > Then you should be able to just refer to it without creating it with
> >> >
> >> > Global.myString = "set me";
> >> >
> >> > john
> >> >
> >> > nice clean examples at www.nicecleanexamples.com
> >> >
> >>
> >>
> >>

>
>
>

 
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
FWSM/PIX and Dynamic PAT using global IP range vs. global interface vs. global IP Hoffa Cisco 1 10-25-2006 06:50 PM
FWSM/PIX and Dynamic PAT using global IP range vs. global interface vs. global IP Hoffa Cisco 0 10-25-2006 01:04 PM
Class A contains class B, class B points to class A Joseph Turian C++ 5 12-30-2005 03:24 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
A parameterized class (i.e. template class / class template) is not a class? christopher diggins C++ 16 05-04-2005 12:26 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57