T
tonyreynolds
I have an asp.net application that needs to spawn a new thread but
return the response back to the user before the thread finishes. My
application works fine on my machine (XP pro) and on a win 2000 server,
but I can't get a thread to start on a new win 2003 server. I've
posted some sample code below. I've made sure that the user this runs
under has permission to write the test file to the c: drive. This code
works on all the servers if I don't start a new thread but call the
WriteFile method directly.
I'm sure I've missed a security setting somewhere, I know 2003 is
supposed to be tied down a little tighter than it's predecessors.
Any help would be appreciated. Thanks in advance!
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.IO;
namespace TestApp
{
/// <summary>
/// Summary description for Test.
/// </summary>
public class Test : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
Response.Write("beginning thread<br>");
ThreadStart ts = new ThreadStart(WriteFile);
Thread t = new Thread(ts);
t.Start();
Response.Write("began thread<br>");
}
private void WriteFile()
{
StreamWriter sw = File.CreateText("c:\\test.txt");
sw.WriteLine("test - "+ DateTime.Now.ToLongTimeString());
sw.Close();
}
#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
}
}
return the response back to the user before the thread finishes. My
application works fine on my machine (XP pro) and on a win 2000 server,
but I can't get a thread to start on a new win 2003 server. I've
posted some sample code below. I've made sure that the user this runs
under has permission to write the test file to the c: drive. This code
works on all the servers if I don't start a new thread but call the
WriteFile method directly.
I'm sure I've missed a security setting somewhere, I know 2003 is
supposed to be tied down a little tighter than it's predecessors.
Any help would be appreciated. Thanks in advance!
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.IO;
namespace TestApp
{
/// <summary>
/// Summary description for Test.
/// </summary>
public class Test : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
Response.Write("beginning thread<br>");
ThreadStart ts = new ThreadStart(WriteFile);
Thread t = new Thread(ts);
t.Start();
Response.Write("began thread<br>");
}
private void WriteFile()
{
StreamWriter sw = File.CreateText("c:\\test.txt");
sw.WriteLine("test - "+ DateTime.Now.ToLongTimeString());
sw.Close();
}
#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
}
}