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