使用线程池进行目录访问(.NET、IIS6)

发布于 2024-10-05 22:41:40 字数 523 浏览 7 评论 0原文

我有一个大型进程要在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浮世清欢 2024-10-12 22:41:40

不幸的是,没有办法解决权限错误,您必须解决它。

为应用程序池分配一个用户帐户(如有必要,创建一个新帐户)并授予该帐户对该文件夹的写入权限。

如果您处于托管环境中,请与管理员联系以帮助您进行设置。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文