What you are trying to achieve there, is called the Singleton Design
Pattern.
I suggest you do some research into it, and any pitfalls it might have.

Regards,
Reuben Bartolo
http://whatiseeinit.blogspot.com/

On 10 February 2012 19:26, Guilherme Utrabo <[email protected]> wrote:

> Hello everybody. Need some help with the "lock" statement.
> I have the following structure on my Global.asax:
>
> private static IList MyList;
> private static object syncObject = new object();
> void Application_PreRequestHandlerExecute(Object sender, EventArgs e)
> {
>       if (MyList == null)
>       {
>             lock (syncObject)
>             {
>                   MyList = new ArrayList();
>                   MyList.Add("test");
>             }
>       }
> }
>
> When my application starts I want to populate "MyList" and then share it
> between the users.
> But I want to make it once. Is my structure really thread safe? Should I
> use the lock on "MyList" instead of using it on the "syncObject"?
>
> Thanks in advance.
>
> Regards,
> Guilherme
>
> --
> You received this message because you are subscribed to the Google
> Groups "DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML
> Web Services,.NET Remoting" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/dotnetdevelopment?hl=en?hl=en
> or visit the group website at http://megasolutions.net
>

-- 
You received this message because you are subscribed to the Google
Groups "DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML
Web Services,.NET Remoting" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/dotnetdevelopment?hl=en?hl=en
or visit the group website at http://megasolutions.net

Reply via email to