Signup Login
Try it for FREE!

Improving ASP.NET Performance Part 10: Application State Management

In 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)

 

  {

 

    lock(_lock)

 

    {

 

        //populate the states    }

 

  }

 

}

 

public void Application_OnStart(object sender, EventArgs e)

 

{

 

  PopulateStates();

 

}

 

%>

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

This entry was posted in Application Performance Management and tagged , , , , , , , , , . Bookmark the permalink.

Trusted by:

trusted by trusted by trusted by trusted by trusted by trusted by trusted by trusted by trusted by trusted by
About Monitis

Monitis GFI is a specialist provider of web and Cloud monitoring services that include website monitoring, site load testing, transaction monitoring, application and database monitoring, Cloud resource monitoring, and server and internal network monitoring within one easy-to-use dashboard. Over 100,000 users worldwide have chosen Monitis as their provider of choice to increase uptime and user experience of their services and products. What makes Monitis' solutions different is that they are fast to deploy, feature-rich in technology and provide a comprehensive single-pane view of on-premise and off-premise infrastructure and applications.

Follow Monitis on Facebook
Follow Monitis on Twitter