请问以下代码哪一句造成资源没有释放 The process cannot access the file

pingosk 2016-11-17 02:24:00

string path = Path.Combine(HttpRuntime.AppDomainAppPath, picurl.TrimStart(new char[1]{'/'}));

//LogManager.getInstance().getLogger(typeof(BaoMingRobot)).Error(path);

String dirPath = Path.Combine(HttpRuntime.AppDomainAppPath, "files111221/toupiao/");

dirPath += ac.SmallVoteId + "/";
if (!Directory.Exists(dirPath))
{
Directory.CreateDirectory(dirPath);
}

string path2 = dirPath + openid + ".jpg";

string pathLogo = dirPath + openid + "_logo.jpg";

if (!string.IsNullOrEmpty(PicUrl1))
{
WebClient myWebClient = new WebClient();
myWebClient.DownloadFile(PicUrl1, pathLogo);
myWebClient.Dispose();
}

//LogManager.getInstance().getLogger(typeof(BaoMingRobot)).Error(path2);

System.Drawing.Image image = System.Drawing.Image.FromFile(path);
//先生成编号
//第一步,很获得图片
using (Graphics g = Graphics.FromImage(image))
{
//g.DrawString("关注之后请回复编号", new Font("宋体", 16),
// Brushes.Black, new PointF(200, 660));
//g.Flush();

if (!string.IsNullOrEmpty(PicUrl1))
{
System.Drawing.Image imageLogo = System.Drawing.Image.FromFile(pathLogo);
// g.DrawImage(imageLogo, new Rectangle(100, 100, image.Width, image.Height), new Rectangle(0, 0, imageLogo.Width, imageLogo.Height), GraphicsUnit.Pixel);
g.DrawImage(imageLogo, new Rectangle(image.Width / 2 - imageLogo.Width / 12, 20, imageLogo.Width * 2 / 12, imageLogo.Height * 2 / 12), new Rectangle(0, 0, imageLogo.Width, imageLogo.Height), GraphicsUnit.Pixel);
imageLogo.Dispose();
}
g.Flush();

g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
g.DrawString(num.ToString(), new Font("黑体", 30,FontStyle.Bold),
Brushes.Red, new PointF(322, 950));

g.Flush();
}
image.Save(path2);
image.Dispose();


 - System.IO.IOException: The process cannot access the file 'C:\webroot\files111221\toupiao\65\oeuv9wiGNe-KH7djQNP9LZCTxlLU_logo.jpg' because it is being used by another process.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
at System.Net.WebClient.DownloadFile(Uri address, String fileName)

...全文
483 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
pingosk 2017-03-19
  • 打赏
  • 举报
回复
时间太长了,我也不记得怎么解决了,先结帖,感觉两位。
  • 打赏
  • 举报
回复
path和path2同名了吧?
正怒月神 2016-11-17
  • 打赏
  • 举报
回复
我觉得你的问题可能是这个。 http://www.cnblogs.com/jxnuxg/articles/736991.html

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧