Reputation: 21667
I've an asp.net page which executes a long running task. So I execute the task in a separate thread and poll the page regularly to check for the status.
public partial class ResultPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(delegate()
{
ProcessItems(parameters);
}));
t.Name = "ThreadInfoPathProcess";
t.Priority = ThreadPriority.Normal;
t.Start();
}
private void ProcessItems(Parameters params)
{
//
//some code
//
//save the result in session and take it from another page
lock (this.Session.SyncRoot)
this.Session[resultid] = result;
}
}
But when I access the session from some another page I'm getting the session variable as null. What could be the problem here?
Upvotes: 1
Views: 491
Reputation: 364409
The correct way to do this is creating windows service where you will schedule your long running processes via remote calls from the web application (WCF - can be local over named pipes). Then your timer will pool the page which will in turn either pool the windows service or check some status record with the result in the database.
Upvotes: 2