In asp.net 2, deleting a folder will cause the application to restart. But today I found that this behavior no longer existed in asp.net 4? I can't find any information about this. Can anybody tell me if this is true? If yes, that's awesome! I hate this application restart behavior in asp.net 2. You can try this:
Debug the following code in asp.net webforms (.net 3.5) and you'll catch the ThreadAbortException. But when you debug it in asp.net webforms (.net 4), you won't catch any exception; everything is fine. I think the reason why I got ThreadAbortException is that I deleted a directory in the thread. Then application restarted, and then the thread got aborted. (Environment: Win8, VS2012, IIS Express)
protected void Page_Load(object sender, EventArgs e)
{
var thread = new Thread(() =>
{
var folderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data\\Test");
var filePath = Path.Combine(folderPath, "test.txt");
if (Directory.Exists(folderPath))
{
Directory.Delete(folderPath, true);
}
Directory.CreateDirectory(folderPath);
System.IO.File.WriteAllText(filePath, "Hello");
try
{
var loop = 100;
while (loop > 0)
{
Thread.Sleep(100);
loop++;
}
}
catch (Exception ex)
{
var msg = ex.Message;
}
});
thread.Start();
Response.Write("Running");
}