7.11. Managing State: The Application Object

There is analogous support for maintaining values across sessions within the Application object. The Global class provides a skeletal definition of an Application_Start() event handler. It is invoked once at the start of the application. This is where we initialize global data for our application. For example, let's provide values to hold total mouse clicks across all sessions:

protected void
Application_Start(Object sender, EventArgs e)
{
      Application.Add( "TotalAnnaCount", 0 );
      Application.Add( "TotalPoohCount", 0 );
      Application.Add( "TotalMissCount", 0 );
}

These values can be accessed concurrently through multiple sessions, so we need to be more careful when writing them. For example, the following ...

Get C# Primer: A Practical Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.