Lock and unlock application state
ApplicationStateLockUnLock.aspx
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e) {
Application.Lock();
int clickCounter = 0;
if(Application["ClickCounter"] !=null)
{
clickCounter = (int)Application["ClickCounter"];
}
clickCounter++;
Application["ClickCounter"] = clickCounter;
Application.UnLock();
Label1.Text = "Button Clicked: " + clickCounter.ToString() + " times";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>asp.net application state example: how to lock and unlock application state in asp.net</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Red">asp.net application state example: Lock and UnLock</h2>
<asp:Label
ID="Label1"
runat="server"
Font-Size="Large"
ForeColor="DodgerBlue"
>
</asp:Label>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
Text="Show Button Click Status"
OnClick="Button1_Click"
Font-Bold="true"
ForeColor="DodgerBlue"
/>
</div>
</form>
</body>
</html>


