I have the following code in my codebehind (aspx.cs):
protected void button1_Click(object sender, EventArgs e)
{
new Thread(delegate() {
try
{
Thread.Sleep(30000); //do nothing for 30 seconds
}
catch (Exception ex)
{
//I AWLAYS get a ThreadAbortException here
//in about 1 second WHY!?!??!
}
}).Start();
}
Does ASP.NET kill all child threads when the request ends?
PS. I predict a lot of "because it's not best practice" answers. I know about best practices of running things in a windows service etc. I'm just curious WHY EXACTLY the thread is being killed in this particular code, given there's no "Response.Redirect", no "Response.End", no pool recycle, no IIS-restart etc etc (typical reasons people are repeating the "background thread in ASP.NET is bad" mantra).
UPDATE: As it turns out it works fine in ASP.NET MVC!!! The thread is aborted in Web-Forms only!! Which is even more weird. Any ideas?