Re: [ADVANCED-DOTNET] Global.asax: versus static variables

Tue, 20 Dec 2005 11:15:58 -0800

OK, the global statics seem to work. I have to try the recycle stuff in IIS.
But that leaves more questions.

1) Is it possible that 2 dotnet webapplications share the same AppDomain?
    (in that case the solution with the static global doesn't work!!)
2) Why should one choose for the <object> tags? I only see disadvantages.
3) How do you guys manage global application variables?

Piewie

---- Original Message ----
From: "David Lanouette" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Tuesday, December 20, 2005 6:58 PM
Subject: Re: [ADVANCED-DOTNET] Global.asax: <object> versus static
variables

> I just wanted to add one more caviat (sp?) to what Ryan said.
>
> For static variables, the runtime guarantees that only one instance is
> created PER APP DOMAIN.
>
> IIRC, If you have recycling configured in IIS6, that is done by
> creating new App Domains.  So, the object /could/ be recreated at any
> time.  And any info you "stored" in that object could be lost (unless
> you do something special to prevent it).
>
> I don't have any idea how recycling would interact with the <object>
> tag.
>
> HTH.
>
>
>
> On 12/20/05, Ryan Heath <[EMAIL PROTECTED]> wrote:
>> Threading problems are the same, your object should be context
>> agnostic and threadsafe.
>>
>> Instance creation is different, with static variables, the runtime
>> guarantees that only one object is created. With application objects,
>> your own program must assure not to create more than one instance.
>>
>> HTH
>> // Ryan
>>
>> On 12/20/05, Peter van der Weerd <[EMAIL PROTECTED]> wrote:
>>> Hello,
>>>
>>> I was used to specifiy global objects int the <object> tag in a
>>> global.asa file.
>>>
>>> It is still possible to do so in the dotnet environment, but I
>>> think its a pain to do so, because you need a lot of casts and the
>>> way you access those global objects is rather verbose. Its
>>> something like
>>>
>>>     MyObject obj =
>>> (MyObject)context.Application.StaticObjects.GetObject("MyObject");
>>>
>>> It is also possible to declare only static variables in a class,
>>> and use them instead of the <object> tag.
>>> One can think of
>>>
>>> public class MyGlobals
>>> {
>>>    public static MyObject myObject = new MyObject();
>>> }
>>>
>>> and then in a ashx or aspx file:
>>>    MyGlobals.MyObject......
>>>
>>> However, I'm not sure what the consequences are.
>>> Can anybody explain what the exact difference is (I mean
>>> differences with respect to threading, instacing, etc)
>>>
>>> Thanks a lot.
>>>
>>> Peter
>>>
>>> ===================================
>>> This list is hosted by DevelopMentor(r)  http://www.develop.com
>>>
>>> View archives and manage your subscription(s) at
>>> http://discuss.develop.com
>>>
>>
>> ===================================
>> This list is hosted by DevelopMentor(r)  http://www.develop.com
>>
>> View archives and manage your subscription(s) at
>> http://discuss.develop.com

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to