I have the following code snippet in a method of my ASP.NET MVC application that tries to delete the directories and their files.
// efetuo processos de remoção de arquivos do banco de dados
await Context.SaveChangesAsync();
var itens = diretorios.Select(x => new
{
x.Id,
x.AreaId
});
ThreadPool.QueueUserWorkItem(x =>
{
var directories = itens
.Select(item => Configurations.Documents.PublicDirectory(item.Id, item.AreaId))
.Where(Directory.Exists);
foreach (var directory in directories)
{
try
{
Directory.Delete(directory, true);
}
catch
{
// Ignore
}
}
});
return RedirectToAction("Index");
I expected that by queuing the routine in ThreadPool
and exiting this method that application (continuity) processing would occur without problems.
So it was during debugging and testing, no problem. However, it already hangs on my web server.
The redirection to Action
Index
works, however, in Index
there is an Ajax request to re-list the files (these are not even fetched on disk, but in the database).
This request is not terminated whereas, as far as I can understand, this routine queued at ThreadPool
does not end. That is, my loading gif keeps popping up until finally the process terminates and then the files and directories are listed.
The application does not open in any other browser while the process does not finish.
What am I doing wrong?