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
> >> >
> >>
> >>
> >>
>
>
>