Blue Theme Orange Theme Green Theme Red Theme
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Home | Forums | ASP.NET 2.0 Tutorials | Web Services | How Do I...? | Class Browser | WPF Quick Starts | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
Search :       Advanced Search »
Home » Blogs Home » Blog Detail

Implement Synchronization in Application State Using ASP.NET

 by Rohatash Kumar on Feb 03, 2012

Application state is a global storage mechanism that is stored on the server and shared for all users. Does not expire. Thus, application state is useful for storing information that needs to be maintained between server round trips and between requests for pages.
Comments: 1 Views: 666 Printable Version 

Application state

Application state is a global storage mechanism that is stored on the server and shared for all users. Does not expire. Thus, application state is useful for storing information that needs to be maintained between server round trips and between requests for pages. We can count how many times a given page has been requested by various clients using an application state. The below code defines that.

protected void Page_Load(object sender, System.EventArgs e)

    {

        int count = 0;

        if (Application("Pagecount") != null)

        {

            count = Convert.ToInt32(Application("Pagecount"));

        }

        count += 1;

        Application("Pagecount") = count;

        Label1.Text = " total Page Visited: " + count.ToString() + "Times";

    }

 

Problem with Above code

How to implement Synchronization in application state?

In the above code, a page counter would probably not keep an accurate count. For example, if two clients requested the page at the same time. Then deadlock will occur. We can avoid deadlock occurrence while we updating application variable by multiple users with help of Lock() and UnLock().

Adding the following code with lock and unlock method.

protected void Page_Load(object sender, System.EventArgs e)

    {

        Application.Lock();

        int count = 0;

        if (Application("Pagecount") != null)

        {

            count = Convert.ToInt32(Application("Pagecount"));

        }

        count += 1;

        Application("Pagecount") = count;

        Application.UnLock();

        Label1.Text = "Total Page Visited: " + count.ToString() + "Times";

    }

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
 
What do you say about this post? Post a comment here
*Title:
*Comment:
 

Each female favorite degree of shoes by JimJarmusch Jim On Mar 15, 2012
Each female favorite degree of shoes, some people like high-heeled, it was like to level with, the key is to dress appropriate. Early autumn period round, flat shoes believe that we can meet some people's tastes. This season, miumiu still follow the guidelines comfortable for the first, plus a lot of fashion elements, sections of flat shoes have their own characteristics, let us enjoy this great season.Glittering vamps, like painted powder princess shoes can be described as cute.The end of a comfortable flat shoes, soft cortex love how wearing on how to wear flat shoes red heart, girl wind diminished, big bright bow.Or special shoes shape, creating a the miumiu non-general refinement. http://www.monsterearphoes.com/

Nevron Gauge for SharePoint
Become a Sponsor

 Blogger's Profile
Age: Not Available
Location:
Title: Developer
Joined: Aug 10, 2010
Education: Masters Degree
 More Blogs from this Blogger
No record available
 Latest Blogs
[Video] OnClose Handler
[Video] Storing and Loading the Window and Toolbar position
The Euclidean Algorithm
Swapping Exe Process
How Exe file is Generated by VS2005 C++ Project?
What is Exe
Header files: Multiple Inclusion problem - Solution B
Header files: Multiple Inclusion problem - Solution A
Header files: Multiple Inclusion problem - Reason
Header files: Multiple Inclusion problem
View all »
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 
6 Months Free & No Setup Fees ASP.NET Hosting!
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.