I have created an ASP.NET web application in which a file needs to be deleted. Below is the code that performs this operation perfectly
File.Delete(path);
However when i tried to do this operation on a background thread like this
Task.Run(() => File.Delete(path));
Then it throws an exception that access to this path is denied. I have tried giving IIS_IUSRS and IUSR full access to the path, but still the error persists. Can someone explain what's going on here. Howcome the file was getting deleted with the first code i.e. on main thread, but not on background thread. Do backgroung threads in C# run with different Identity?