使用线程池进行目录访问(.NET、IIS6)
我有一个大型进程要在 Web 应用程序的后台进行,并且主线程超时,因此我决定采用线程池路线。不幸的是,这个过程的一部分是写入和删除大量文件。但是,它使用的线程没有写入此目录的权限。
这里有一个小片段:
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
}
我总是在本地计算机上遇到 IO 异常,在 IIS 上它显示“线程正在中止”——每当执行 2 分钟时我都会遇到同样的错误。
请帮忙!谢谢!
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 files. 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,没有办法解决权限错误,您必须解决它。
为应用程序池分配一个用户帐户(如有必要,创建一个新帐户)并授予该帐户对该文件夹的写入权限。
如果您处于托管环境中,请与管理员联系以帮助您进行设置。
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.