Improving ASP.NET Performance Part 10: Application State Management

Improving ASP.NET Performance Part 10: Application State ManagementIn this article we’ll discuss Application State Management. Application state is used to store application-wide static information. If you use application state, use the following guidelines to ensure your application runs optimally:

·         Use static properties instead of the Application object to store application state.

·         Use application state to share static, read-only data.

·         Do not store STA COM objects in application state.

Use Static Properties Instead of the Application Object to Store Application State

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)








        //populate the states    }






public void Application_OnStart(object sender, EventArgs e)









Use Application State to Share Static, Read-Only Data

Application state is application-wide and specific to a server. Even though you can store read-write data, it advisable to only store read-only data to avoid server affinity. Consider using the Cache object. The Cache object is a better alternative for read-only data.

Do Not Store STA COM Objects in Application State

Storing STA COM objects in application state bottlenecks your application because the application uses a single thread of execution when it accesses the component. Avoid storing STA COM objects in application state.

In our next article we’ll talk about guidelines for Session State Management

You might also like