gpt4 book ai didi

c# - 系统资源不足,无法完成请求的服务

转载 作者:太空宇宙 更新时间:2023-11-03 14:02:00 25 4
gpt4 key购买 nike

我在 Windows Server 2003 机器上的 IIS 6 中托管了一个 Web 应用程序,必须处理 2 个大约 7-8mb 的大型 PDF 文件,这些文件由网站从网络共享中读取,并将字节传递给 WCF 服务保存在别处。

这是我用来读取文件的代码:

public static byte[] ReadFile(string filePath)
{
int count;
int sum = 0;
byte[] buffer;
FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read);

try
{
int length = (int)stream.Length;
buffer = new byte[length];

while ((count = stream.Read(buffer, sum, length - sum)) > 0)
sum += count;

return buffer;
}
catch (Exception)
{
throw;
}
finally
{
stream.Close();
stream.Dispose();
}
}

stream.Read() 上抛出一个错误,错误是:

Insufficient system resources exist to complete the requested service

此代码在我的开发环境中有效,但一旦我发布到我们的生产环境中,我们就会收到此错误消息。我已经看到这个错误在搜索中出现了几次,解决方法是使用 File.Move() 但我们不能这样做,因为文件需要传递给 WCF 服务方法.

IIS6 中是否需要更改某些内容以允许在读取文件时在内存中保留 15-20mb?或者还有其他需要配置的东西吗?

有什么想法吗?

最佳答案

看这个:

Why I need to read file piece by piece to buffer?

看起来你正在读取整个文件,没有缓冲..

buffer = new byte[length];

最好的问候。

关于c# - 系统资源不足,无法完成请求的服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10513722/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com