I
Ilia
Hi folks,
I have some problems with ASP.NET Session State. The
following simple program runs well if the Session State
set as "InProc". If I switch to "SQLServer", the changes,
made by the second thread, are lost. Any idea?
I use VS.NET 2003 on Windows Server 2003 with hot fixes
(as of 30-Oct-2003) and SQL Server 2000 SP 3a.
Thanks.
Ilia
---- WebForm1.aspx
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false" Inherits="TestSqlState.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<META HTTP-EQUIV="Refresh" CONTENT="3;
URL=">
<meta name="GENERATOR" Content="Microsoft
Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript"
content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post"
runat="server">
<asp:Label id="lbl"
runat="server">Label</asp:Label>
</form>
</body>
</HTML>
---- WebForm1.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Threading;
using System.Timers;
namespace TestSqlState
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label
lbl;
private Thread m_Thread = null;
private void Page_Load(object sender,
System.EventArgs e)
{
lock(Session.SyncRoot)
{
if(Session["lbl"] == null)
Session["lbl"]
= "Start";
lbl.Text = (string) Session
["lbl"];
}
m_Thread = new Thread(new
ThreadStart(t1));
m_Thread.Start();
lock(Session.SyncRoot)
{
Session["lbl"] = (string)
Session["lbl"] + "<br>Started...";
}
}
private void t1()
{
System.Timers.Timer TimeOutTimer =
new System.Timers.Timer(2000);
ElapsedEventHandler
TimeOutDelegate = new ElapsedEventHandler
(TimeOutEventProcessor);
TimeOutTimer.Elapsed +=
TimeOutDelegate;
TimeOutTimer.Enabled = true;
}
private void TimeOutEventProcessor(Object
myObject, ElapsedEventArgs TimeOutArgs)
{
lock(Session.SyncRoot)
{
Session["lbl"] = (string)
Session["lbl"] + "<br>Timer...";
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required
by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support -
do not modify
/// the contents of this method with the
code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new
System.EventHandler(this.Page_Load);
}
#endregion
}
}
I have some problems with ASP.NET Session State. The
following simple program runs well if the Session State
set as "InProc". If I switch to "SQLServer", the changes,
made by the second thread, are lost. Any idea?
I use VS.NET 2003 on Windows Server 2003 with hot fixes
(as of 30-Oct-2003) and SQL Server 2000 SP 3a.
Thanks.
Ilia
---- WebForm1.aspx
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false" Inherits="TestSqlState.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<META HTTP-EQUIV="Refresh" CONTENT="3;
URL=">
<meta name="GENERATOR" Content="Microsoft
Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript"
content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post"
runat="server">
<asp:Label id="lbl"
runat="server">Label</asp:Label>
</form>
</body>
</HTML>
---- WebForm1.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Threading;
using System.Timers;
namespace TestSqlState
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label
lbl;
private Thread m_Thread = null;
private void Page_Load(object sender,
System.EventArgs e)
{
lock(Session.SyncRoot)
{
if(Session["lbl"] == null)
Session["lbl"]
= "Start";
lbl.Text = (string) Session
["lbl"];
}
m_Thread = new Thread(new
ThreadStart(t1));
m_Thread.Start();
lock(Session.SyncRoot)
{
Session["lbl"] = (string)
Session["lbl"] + "<br>Started...";
}
}
private void t1()
{
System.Timers.Timer TimeOutTimer =
new System.Timers.Timer(2000);
ElapsedEventHandler
TimeOutDelegate = new ElapsedEventHandler
(TimeOutEventProcessor);
TimeOutTimer.Elapsed +=
TimeOutDelegate;
TimeOutTimer.Enabled = true;
}
private void TimeOutEventProcessor(Object
myObject, ElapsedEventArgs TimeOutArgs)
{
lock(Session.SyncRoot)
{
Session["lbl"] = (string)
Session["lbl"] + "<br>Timer...";
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required
by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support -
do not modify
/// the contents of this method with the
code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new
System.EventHandler(this.Page_Load);
}
#endregion
}
}