Hey guys, I’m trying to get threading to work in ASP.NET but for some reason it keeps crashing my local server, and simply does not work at all when uploaded online. Here’s the code:
protected void testThread()
{
for (int i = 0; i < 10; i++)
{
Response.Write("Threading! <br/><br/>");
Thread.Sleep(500);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Thread oThread = new Thread(testThread);
oThread.Priority = ThreadPriority.Lowest; //Tried with and without this
// Start the thread
oThread.Start();
}
Any ideas?
Like what @Daniel said,
Responsemay already have terminated by the time your thread runs. The solution is to keep the connection alive while the thread runs. We can do that by assigning and asynchronous task to do the job.You might want to try this as well, though I’m not sure whether it works or not, but I suspect it will: