我正在尝试使用下面的代码解压一个文件。
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();
}
}我的问题是:
我已经发布了我的web项目,并托管在IIS Express-8中。在调用此UnZip方法时,内存使用量会超过600MB,并且在从该方法中退出超过一个小时后,内存使用量永远不会下降。因此,如果我再次调用相同的方法,我会得到MemoryOutOfException错误,因为在默认情况下,iis express有800MB,所以我会得到这个错误。
我不想增加IIS Express的内存大小。也许我在代码中犯了一些错误,但我找不到问题。
帮助我找到问题并解决我的问题。
发布于 2015-02-17 18:17:56
我会将"zip.Close();“放在使用块的内部
https://stackoverflow.com/questions/28556475
复制相似问题