I have a large process to take place in the background of a web application and it was timing out on the main thread, so I've decided to take the Threadpool route. Unfortunately, part of this process is writing and deleting lots of f开发者_JAVA百科iles. The thread that it uses, however, doesn't have permissions to write to this directory.
Here's a little snippet:
public void BeginMosaicCreation(string[] files, string outputPath)
{
this.Files = files;
this.OutputPath = outputPath;
ThreadPool.QueueUserWorkItem(new WaitCallback(Create));
}
private void Create(object a)
{
// Does some stuff including clearing directories and writing files
}
I always get an IO exception on my local machine, and on IIS it's saying "Thread was being aborted" - the same error I got before whenever it got to 2 minutes of execution.
Please help! Thanks!
Unfortunately there's no way around the permission error, you have to address it.
Assign the application pool a user account (Create a new one if necessary) and grant that account write permission on that folder.
If you're in a hosted environment, speak to the admins about helping you set this up.
精彩评论