Reputation: 2509
What happens if a long running page is closed by the user before he has received a response?
Does the page continue to run in the it's thread or is the thread terminated as soon as the user closes the page?
Upvotes: 0
Views: 520
Reputation: 2586
Oded is correct, the request keeps processing long after the user has browsed away or closed their browser window. For fun try this:
protected void Page_Load(object sender, EventArgs e)
{
for (int count = 0; count < 100; count++)
{
Debug.WriteLine("Processing {0}, IsClientConnected={1}", count, Response.IsClientConnected);
Response.Write(string.Format("Processing {0}<br/>", count));
Response.Flush();
Thread.Sleep(1000);
}
Response.Write("<h1>Done<h1/>");
}
The request keeps processing after navigating away, but the IsClientConnected property changes to false. You can use this to your advantage, but you have to write code to take advantage of that, normally for long running requests.
Processing 0, IsClientConnected=True Processing 1, IsClientConnected=True Processing 2, IsClientConnected=True Processing 3, IsClientConnected=True Processing 4, IsClientConnected=True Processing 5, IsClientConnected=True Processing 6, IsClientConnected=True Processing 7, IsClientConnected=True Processing 8, IsClientConnected=True Processing 9, IsClientConnected=True Processing 10, IsClientConnected=True Processing 11, IsClientConnected=True Processing 12, IsClientConnected=True Processing 13, IsClientConnected=False Processing 14, IsClientConnected=False Processing 15, IsClientConnected=False Processing 16, IsClientConnected=False Processing 17, IsClientConnected=False
Upvotes: 1