Home All Groups Group Topic Archive Search About
Author
20 Feb 2007 4:21 PM
ThunderMusic
Hi,
I always refer to this page to know the order of events in a page :
http://weblogs.asp.net/jeff/archive/2004/07/04/172683.aspx  but this time,
I'm mystified...

I have a Control called "ImagePreloader" I placed in the head of my
MasterPage (aspx)...  in the Init of the "ImagePreloader", I put the
instance in the HTTPContext.Current.Cache... and provide a static method so
other controls can have access to the ImagePreloader...  On a P IV 3Ghz,
WinXP Pro SP2, IIS 5, everything works fine...  On a P III 1Ghz, WinXP Pro
SP2, IIS 5, It sometimes happen that when other controls want to get the
instance in their PreRender events (so way after the OnInit), the instance
has never been created... If I put a breakpoint in the OnInit of the
ImagePreloader, it never gets there even tought it's a control in the aspx
of the masterpage... Maybe it's not related to speed at all, but I really
don't know what can cause this...

can anyone help me please?

Thanks

ThunderMusic

Author
20 Feb 2007 11:51 PM
Milosz Skalecki [MCAD]
Hi there,

I think entitre logic yore are based on is wrong. What do you mean by 'I put
the instance in the HTTPContext.Current.Cache'? Could you provide some code
to show us what are you doing? I suspect you put an instance to cache, and
this instance is reused in every request (which is not acceptable because
different threads work on the same control ?!) did i get you right?
--
Milosz


Show quote
"ThunderMusic" wrote:

> Hi,
> I always refer to this page to know the order of events in a page :
> http://weblogs.asp.net/jeff/archive/2004/07/04/172683.aspx  but this time,
> I'm mystified...
>
> I have a Control called "ImagePreloader" I placed in the head of my
> MasterPage (aspx)...  in the Init of the "ImagePreloader", I put the
> instance in the HTTPContext.Current.Cache... and provide a static method so
> other controls can have access to the ImagePreloader...  On a P IV 3Ghz,
> WinXP Pro SP2, IIS 5, everything works fine...  On a P III 1Ghz, WinXP Pro
> SP2, IIS 5, It sometimes happen that when other controls want to get the
> instance in their PreRender events (so way after the OnInit), the instance
> has never been created... If I put a breakpoint in the OnInit of the
> ImagePreloader, it never gets there even tought it's a control in the aspx
> of the masterpage... Maybe it's not related to speed at all, but I really
> don't know what can cause this...
>
> can anyone help me please?
>
> Thanks
>
> ThunderMusic
>
>
>
Author
21 Feb 2007 12:39 PM
ThunderMusic
Hi,
I think you didn't get me right, but maybe it's me that didn't get the thing
right...  I put the instance in the HTTPContext so all requests (from other
controls on the page) from this request (this user request to the page) have
an instance to work with... I want it to work as a singleton, but for one
webrequest only... just like the ScriptManager of ASP.NET Ajax (which I
don't use)...  I think I've done it tought...  I finally found the problem
was reproduced everytime I hit the reload button, so I looked at what was
called after that and surprisingly, everything is called, but the instance
does not stay in cache after the constructor, neither after the OnInit
event, but it does after the OnLoad event (go figure), so I put it there,
because my controls use it in the PreRender anyway... ;)

I use exactly this line in the constructor and the OnLoad of the
ImagePreloader WebControl :
    HttpContext.Current.Cache["ImagePreloader"] = this;

Thanks to all, and I hope I helped others if they need this kind of
behavior...

ThunderMusic

Show quote
"Milosz Skalecki [MCAD]" <mily242@DONTLIKESPAMwp.pl> wrote in message
news:7E214D6D-AFDA-4F46-8243-C2D825251960@microsoft.com...
> Hi there,
>
> I think entitre logic yore are based on is wrong. What do you mean by 'I
> put
> the instance in the HTTPContext.Current.Cache'? Could you provide some
> code
> to show us what are you doing? I suspect you put an instance to cache, and
> this instance is reused in every request (which is not acceptable because
> different threads work on the same control ?!) did i get you right?
> --
> Milosz
>
>
> "ThunderMusic" wrote:
>
>> Hi,
>> I always refer to this page to know the order of events in a page :
>> http://weblogs.asp.net/jeff/archive/2004/07/04/172683.aspx  but this
>> time,
>> I'm mystified...
>>
>> I have a Control called "ImagePreloader" I placed in the head of my
>> MasterPage (aspx)...  in the Init of the "ImagePreloader", I put the
>> instance in the HTTPContext.Current.Cache... and provide a static method
>> so
>> other controls can have access to the ImagePreloader...  On a P IV 3Ghz,
>> WinXP Pro SP2, IIS 5, everything works fine...  On a P III 1Ghz, WinXP
>> Pro
>> SP2, IIS 5, It sometimes happen that when other controls want to get the
>> instance in their PreRender events (so way after the OnInit), the
>> instance
>> has never been created... If I put a breakpoint in the OnInit of the
>> ImagePreloader, it never gets there even tought it's a control in the
>> aspx
>> of the masterpage... Maybe it's not related to speed at all, but I really
>> don't know what can cause this...
>>
>> can anyone help me please?
>>
>> Thanks
>>
>> ThunderMusic
>>
>>
>>
Author
21 Feb 2007 1:22 PM
ThunderMusic
ok, I said it too quick...  it does not always work... It crashes regularly
on Netscape...  and it goes in the constructor, it goes in the OnLoad, then
when my controls request for it in their OnPreRender, it says it does not
exist...  Anyone have an idea of what could be the cause?  what is the use
of putting something the the Context cache if it does not stay there? Where
should I put it then?

Thanks

ThunderMusic


Show quote
"ThunderMusic" <NoSpAmdanlatathotmaildotcom@NoSpAm.com> wrote in message
news:OuF04TbVHHA.4832@TK2MSFTNGP04.phx.gbl...
> Hi,
> I think you didn't get me right, but maybe it's me that didn't get the
> thing right...  I put the instance in the HTTPContext so all requests
> (from other controls on the page) from this request (this user request to
> the page) have an instance to work with... I want it to work as a
> singleton, but for one webrequest only... just like the ScriptManager of
> ASP.NET Ajax (which I don't use)...  I think I've done it tought...  I
> finally found the problem was reproduced everytime I hit the reload
> button, so I looked at what was called after that and surprisingly,
> everything is called, but the instance does not stay in cache after the
> constructor, neither after the OnInit event, but it does after the OnLoad
> event (go figure), so I put it there, because my controls use it in the
> PreRender anyway... ;)
>
> I use exactly this line in the constructor and the OnLoad of the
> ImagePreloader WebControl :
>    HttpContext.Current.Cache["ImagePreloader"] = this;
>
> Thanks to all, and I hope I helped others if they need this kind of
> behavior...
>
> ThunderMusic
>
> "Milosz Skalecki [MCAD]" <mily242@DONTLIKESPAMwp.pl> wrote in message
> news:7E214D6D-AFDA-4F46-8243-C2D825251960@microsoft.com...
>> Hi there,
>>
>> I think entitre logic yore are based on is wrong. What do you mean by 'I
>> put
>> the instance in the HTTPContext.Current.Cache'? Could you provide some
>> code
>> to show us what are you doing? I suspect you put an instance to cache,
>> and
>> this instance is reused in every request (which is not acceptable because
>> different threads work on the same control ?!) did i get you right?
>> --
>> Milosz
>>
>>
>> "ThunderMusic" wrote:
>>
>>> Hi,
>>> I always refer to this page to know the order of events in a page :
>>> http://weblogs.asp.net/jeff/archive/2004/07/04/172683.aspx  but this
>>> time,
>>> I'm mystified...
>>>
>>> I have a Control called "ImagePreloader" I placed in the head of my
>>> MasterPage (aspx)...  in the Init of the "ImagePreloader", I put the
>>> instance in the HTTPContext.Current.Cache... and provide a static method
>>> so
>>> other controls can have access to the ImagePreloader...  On a P IV 3Ghz,
>>> WinXP Pro SP2, IIS 5, everything works fine...  On a P III 1Ghz, WinXP
>>> Pro
>>> SP2, IIS 5, It sometimes happen that when other controls want to get the
>>> instance in their PreRender events (so way after the OnInit), the
>>> instance
>>> has never been created... If I put a breakpoint in the OnInit of the
>>> ImagePreloader, it never gets there even tought it's a control in the
>>> aspx
>>> of the masterpage... Maybe it's not related to speed at all, but I
>>> really
>>> don't know what can cause this...
>>>
>>> can anyone help me please?
>>>
>>> Thanks
>>>
>>> ThunderMusic
>>>
>>>
>>>
>
>
Author
21 Feb 2007 3:04 PM
Milosz Skalecki [MCAD]
Hi again

I'm afraid i got you right.
HttpContext.Current.Cache["ImagePreloader"] = this;
Adds instance to cache and will be used in many request threads so don't
expect it's gonna work.  I think you misused cache with context items - it
should have been:
HttpContext.Current.Items["ImagePreloader"].

In addtion to that there is better way to access current request execution
Context from web user control:

this.Context.Items["ImagePreloader"]

or from web custom control:

this.Context.Items["ImagePreloader"]

Hope it's clear now.
--
Milosz


Show quote
"ThunderMusic" wrote:

> Hi,
> I think you didn't get me right, but maybe it's me that didn't get the thing
> right...  I put the instance in the HTTPContext so all requests (from other
> controls on the page) from this request (this user request to the page) have
> an instance to work with... I want it to work as a singleton, but for one
> webrequest only... just like the ScriptManager of ASP.NET Ajax (which I
> don't use)...  I think I've done it tought...  I finally found the problem
> was reproduced everytime I hit the reload button, so I looked at what was
> called after that and surprisingly, everything is called, but the instance
> does not stay in cache after the constructor, neither after the OnInit
> event, but it does after the OnLoad event (go figure), so I put it there,
> because my controls use it in the PreRender anyway... ;)
>
> I use exactly this line in the constructor and the OnLoad of the
> ImagePreloader WebControl :
>     HttpContext.Current.Cache["ImagePreloader"] = this;
>
> Thanks to all, and I hope I helped others if they need this kind of
> behavior...
>
> ThunderMusic
>
> "Milosz Skalecki [MCAD]" <mily242@DONTLIKESPAMwp.pl> wrote in message
> news:7E214D6D-AFDA-4F46-8243-C2D825251960@microsoft.com...
> > Hi there,
> >
> > I think entitre logic yore are based on is wrong. What do you mean by 'I
> > put
> > the instance in the HTTPContext.Current.Cache'? Could you provide some
> > code
> > to show us what are you doing? I suspect you put an instance to cache, and
> > this instance is reused in every request (which is not acceptable because
> > different threads work on the same control ?!) did i get you right?
> > --
> > Milosz
> >
> >
> > "ThunderMusic" wrote:
> >
> >> Hi,
> >> I always refer to this page to know the order of events in a page :
> >> http://weblogs.asp.net/jeff/archive/2004/07/04/172683.aspx  but this
> >> time,
> >> I'm mystified...
> >>
> >> I have a Control called "ImagePreloader" I placed in the head of my
> >> MasterPage (aspx)...  in the Init of the "ImagePreloader", I put the
> >> instance in the HTTPContext.Current.Cache... and provide a static method
> >> so
> >> other controls can have access to the ImagePreloader...  On a P IV 3Ghz,
> >> WinXP Pro SP2, IIS 5, everything works fine...  On a P III 1Ghz, WinXP
> >> Pro
> >> SP2, IIS 5, It sometimes happen that when other controls want to get the
> >> instance in their PreRender events (so way after the OnInit), the
> >> instance
> >> has never been created... If I put a breakpoint in the OnInit of the
> >> ImagePreloader, it never gets there even tought it's a control in the
> >> aspx
> >> of the masterpage... Maybe it's not related to speed at all, but I really
> >> don't know what can cause this...
> >>
> >> can anyone help me please?
> >>
> >> Thanks
> >>
> >> ThunderMusic
> >>
> >>
> >>
>
>
>
Author
21 Feb 2007 7:50 PM
ThunderMusic
thanks a lot, I'll try this...  I knew I was missing something...  thanks
I'll let you know if it works...


Show quote
"Milosz Skalecki [MCAD]" <mily242@DONTLIKESPAMwp.pl> wrote in message
news:2FFA66B9-145F-45AE-A2B8-F25882F2D035@microsoft.com...
> Hi again
>
> I'm afraid i got you right.
> HttpContext.Current.Cache["ImagePreloader"] = this;
> Adds instance to cache and will be used in many request threads so don't
> expect it's gonna work.  I think you misused cache with context items - it
> should have been:
> HttpContext.Current.Items["ImagePreloader"].
>
> In addtion to that there is better way to access current request execution
> Context from web user control:
>
> this.Context.Items["ImagePreloader"]
>
> or from web custom control:
>
> this.Context.Items["ImagePreloader"]
>
> Hope it's clear now.
> --
> Milosz
>
>
> "ThunderMusic" wrote:
>
>> Hi,
>> I think you didn't get me right, but maybe it's me that didn't get the
>> thing
>> right...  I put the instance in the HTTPContext so all requests (from
>> other
>> controls on the page) from this request (this user request to the page)
>> have
>> an instance to work with... I want it to work as a singleton, but for one
>> webrequest only... just like the ScriptManager of ASP.NET Ajax (which I
>> don't use)...  I think I've done it tought...  I finally found the
>> problem
>> was reproduced everytime I hit the reload button, so I looked at what was
>> called after that and surprisingly, everything is called, but the
>> instance
>> does not stay in cache after the constructor, neither after the OnInit
>> event, but it does after the OnLoad event (go figure), so I put it there,
>> because my controls use it in the PreRender anyway... ;)
>>
>> I use exactly this line in the constructor and the OnLoad of the
>> ImagePreloader WebControl :
>>     HttpContext.Current.Cache["ImagePreloader"] = this;
>>
>> Thanks to all, and I hope I helped others if they need this kind of
>> behavior...
>>
>> ThunderMusic
>>
>> "Milosz Skalecki [MCAD]" <mily242@DONTLIKESPAMwp.pl> wrote in message
>> news:7E214D6D-AFDA-4F46-8243-C2D825251960@microsoft.com...
>> > Hi there,
>> >
>> > I think entitre logic yore are based on is wrong. What do you mean by
>> > 'I
>> > put
>> > the instance in the HTTPContext.Current.Cache'? Could you provide some
>> > code
>> > to show us what are you doing? I suspect you put an instance to cache,
>> > and
>> > this instance is reused in every request (which is not acceptable
>> > because
>> > different threads work on the same control ?!) did i get you right?
>> > --
>> > Milosz
>> >
>> >
>> > "ThunderMusic" wrote:
>> >
>> >> Hi,
>> >> I always refer to this page to know the order of events in a page :
>> >> http://weblogs.asp.net/jeff/archive/2004/07/04/172683.aspx  but this
>> >> time,
>> >> I'm mystified...
>> >>
>> >> I have a Control called "ImagePreloader" I placed in the head of my
>> >> MasterPage (aspx)...  in the Init of the "ImagePreloader", I put the
>> >> instance in the HTTPContext.Current.Cache... and provide a static
>> >> method
>> >> so
>> >> other controls can have access to the ImagePreloader...  On a P IV
>> >> 3Ghz,
>> >> WinXP Pro SP2, IIS 5, everything works fine...  On a P III 1Ghz, WinXP
>> >> Pro
>> >> SP2, IIS 5, It sometimes happen that when other controls want to get
>> >> the
>> >> instance in their PreRender events (so way after the OnInit), the
>> >> instance
>> >> has never been created... If I put a breakpoint in the OnInit of the
>> >> ImagePreloader, it never gets there even tought it's a control in the
>> >> aspx
>> >> of the masterpage... Maybe it's not related to speed at all, but I
>> >> really
>> >> don't know what can cause this...
>> >>
>> >> can anyone help me please?
>> >>
>> >> Thanks
>> >>
>> >> ThunderMusic
>> >>
>> >>
>> >>
>>
>>
>>

AddThis Social Bookmark Button