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";
}
CodeaddictionPosted May 27, 2013, 2:10 PM
nice
JimJarmusch JimPosted Mar 15, 2012, 5:50 AM
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/