You should store data in static members of the application class instead of in the Application object. This increases performance because you can access a static variable faster than you can access an item in the Application dictionary. The following is a simplified example.
private static string[] _states[];
private static object _lock = new object();
public static string[] States
{
get {return _states;}
}
public static void PopulateStates()
{
//ensure this is thread safe
if(_states == null)
{
lock(_lock)
{
//populate the states… }
}
}
public void Application_OnStart(object sender, EventArgs e)
{
PopulateStates();
}
Analyse if the lock is needed in the Global asax...
ReplyDelete