我随机得到(在实时环境中,每 2 周一次,使用非常活跃和努力工作的 Windows 服务,它每天调整大约 50000 多张图像) AccessViolationException:试图读取或写入受保护的内存。这通常表明其他内存已损坏。
堆栈跟踪是:堆栈:
at WebSupergoo.ABCpdf7.Internal.NDoc._Clear(IntPtr inDoc)
at WebSupergoo.ABCpdf7.Internal.NDoc.Clear(IntPtr inDoc)
at WebSupergoo.ABCpdf7.Doc.Clear()
at WebSupergoo.ImageGlue7.Canvas.Dispose(Boolean disposing)
at WebSupergoo.ImageGlue7.Canvas.Dispose()
at XXXXX.Classes.Imaging.Image.Resize(Int32 width, Int32 height, Boolean addTransparent) in <path>\Image.cs:line 149
at XXXXX.Classes.XXXXX.Object.Import.Media.CreateImageScale(String destDir, Int32 width) in <path>\Media.cs:line 272
at XXXXX.Classes.XXXXX.Object.Import.Media.CreateResizedImages(String threadId) in <path>\Media.cs:line 242
at XXXXX.Classes.XXXXX.Object.Import.Threading.ResizeThread.Run(Object o) in <path>\ResizeThread.cs:line 38
这是调整大小方法的代码:
public void Resize(int width, int height, bool addTransparent)
{
using (Canvas tempCanvas = new Canvas())
{
DrawOptions options = new DrawOptions();
if (height == 0)
{
if (width <= Width)
{
options.Limit = new Size(width, 0);
}
else
{
double scale = (double)width / (double)Width;
options.Transform.Magnify(scale, scale, 0, 0);
}
}
else if (width == 0)
{
if (height <= Height)
{
options.Limit = new Size(0, height);
}
else
{
double scale = (double)height / (double)Height;
options.Transform.Magnify(scale, scale, 0, 0);
}
}
else
{
double scaleX = (double)width / (double)Width;
double scaleY = (double)height / (double)Height;
options.Transform.Magnify(scaleX, scaleY, 0, 0);
}
//add transparency if set.
if (addTransparent)
options.Transparency = true;
tempCanvas.DrawImage(CurrentImage, options);
CurrentImage = tempCanvas.ToImage();
} <<<<---- HERE WE GET THE EXCEPTION ON THE DISPOSE
}
任何人都可以帮我解决为什么我会收到这个错误,或者我可以做些什么。