<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import namespace="System.Threading" %>
<%@ Import namespace="System.Diagnostics" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat=server >
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session["TestKey"] = DateTime.Now.ToLongTimeString();
Thread myThread = new Thread(new ThreadStart(DoWork));
myThread.Start();
lblTime.Text = "Page Loaded at " + Session["TestKey"].ToString();
}
}
public void DoWork()
{
System.Diagnostics.Trace.WriteLine("Working thread...");
Thread.Sleep(5000);//5 sec
throw new ApplicationException("ThrowException =true");
}
protected void btnGetSession_Click(object sender, EventArgs e)
{
lblFromSession.Text = "From Session Page Loaded at " + Session["TestKey"].ToString();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
Throw Exception test
<asp:Label ID="lblTime" runat="server" Text="Label"></asp:Label>
<br />
<asp:Label ID="lblFromSession" runat="server" Text=""></asp:Label>
<br />
<asp:Button ID="btnGetSession" runat="server" OnClick="btnGetSession_Click" Text="Get Session" /></div>
</form>
</body>
</html>