我正在尝试使用以下代码解压缩文件。
public static void UnZip(string zipFile, string folderPath)
{
using (ZipArchive zip = new ZipArchive())
{
//Loads the zip file.
zip.Open(Path.GetFullPath(zipFile));
//Saving the contents of zip file to disk.
for (int i = 0; i < zip.Count; i++)
{
using (ZipArchiveItem item = zip[i])
{
if (!Directory.Exists(folderPath))
Directory.CreateDirectory(folderPath);
string itemName = folderPath + item.ItemName;
using (FileStream fs = new FileStream(itemName, FileMode.OpenOrCreate,
FileAccess.ReadWrite))
{
MemoryStream ms = item.DataStream as MemoryStream;
ms.WriteTo(fs);
fs.Flush();
ms.Close();
}
}
}
zip.Close();
}
}
我的问题:
我已发布我的网络项目并托管在IIS Express-8中。在调用此UnZip
方法时,内存使用率超过600MB
,并且在从方法中退出超过一小时后,它永远不会下拉。所以,如果我再次调用相同的方法,我会收到MemoryOutOfException
错误,因为默认情况下iis express有800MB
所以我收到错误。
我不想增加IIS Express
的内存大小。可能是我在代码中犯了一些错误,但我找不到问题。
帮我找到问题并解决我的问题。
答案 0 :(得分:0)
我会把&#34; zip.Close();&#34;内部使用块