SharpMap System.AccessViolationException

时间:2014-08-04 07:59:24

标签: c# .net sharpmap

我在窗口服务中使用SharpMap。我正在使用该库生成一个地图,然后从中创建一个图像并将其添加到Excel文件中。代码在Quartz.net任务中运行。

当我调用SharpMap.Map.GetMap()并破坏我的服务时发生错误(请参阅下面的错误报告和堆栈调用)。

这种情况时不时发生(可能是数据问题?)。还要注意,我在处理地图时遇到了一些问题,所以在调用函数之前我就放了一些延迟(System.Threading.Thread.Sleep(5000);)。

我正在生成几个这样的图像,并且错误(上次发生)是在几次(~10次)迭代之后。为了不重新创建和格式化地图的“静态图层”(SharpMap.Map),每次我只添加和删除“动态”图层并在每次迭代中调整一些特征。

有没有办法找出错误的原因?

有没有办法优雅地处理这种异常?

Windows CMS错误报告+堆栈跟踪:

  

应用程序:NePTune.WinService.exe

     

框架版本:v4.0.30319

     

描述:由于未处理的异常,该进程已终止。

     

异常信息:System.AccessViolationException

     

堆栈:

at System.Drawing.SafeNativeMethods+Gdip.GdipPathIterNextSubpathPath(System.Runtime.InteropServices.HandleRef, Int32 ByRef, System.Runtime.InteropServices.HandleRef, Boolean ByRef) 
at System.Drawing.SafeNativeMethods+Gdip.GdipPathIterNextSubpathPath(System.Runtime.InteropServices.HandleRef, Int32 ByRef, System.Runtime.InteropServices.HandleRef, Boolean ByRef) 
at System.Drawing.Drawing2D.GraphicsPathIterator.NextSubpath(System.Drawing.Drawing2D.GraphicsPath, Boolean ByRef) 
at SharpMap.Rendering.Symbolizer.WarpPathToPath.Warp(System.Drawing.Drawing2D.GraphicsPath, System.Drawing.Drawing2D.GraphicsPath, Boolean, Single) 
at SharpMap.Rendering.Symbolizer.WarpPathToPath.DrawString(System.Drawing.Graphics, System.Drawing.Pen, System.Drawing.Brush, System.String, System.Drawing.FontFamily, Int32, Single, System.Drawing.StringFormat, Boolean, System.Drawing.Drawing2D.GraphicsPath) 
at SharpMap.Layers.LabelLayer.Render(System.Drawing.Graphics, SharpMap.Map) 
at SharpMap.Map.RenderMap(System.Drawing.Graphics) 
at SharpMap.Map.GetMap() 
at NePTune.Logic.Algorithms.UlInterference.UlInterferenceReportWriter.CreateClusterMap(System.Collections.Generic.List1<NePTune.Data.SectorGeoDetails>, System.Collections.Generic.Dictionary2<Int32,Double>, Int32, System.Collections.Generic.IEnumerable1<NePTune.Data.SectorGeoDetails>, Boolean) 
at NePTune.Logic.Algorithms.UlInterference.UlInterferenceReportWriter.CreateInterferenceClusterWorksheets(OfficeOpenXml.ExcelPackage, System.Collections.Generic.List1<NePTune.Logic.Algorithms.UlInterference.UlInterferenceCluster>, System.Collections.Generic.Dictionary2<Int32,NePTune.Data.SectorGeoDetails>, System.Collections.Generic.Dictionary2<Int32,NePTune.Logic.Algorithms.UlInterference.CellMeasurementList>) 
at NePTune.Logic.Algorithms.UlInterference.UlInterferenceReportWriter.CreateReport(System.Collections.Generic.List1<NePTune.Logic.Algorithms.UlInterference.CellUlInterferenceResults>, System.Collections.Generic.List1<NePTune.Logic.Algorithms.UlInterference.UlInterferenceCluster>, System.Collections.Generic.Dictionary2<Int32,NePTune.Data.SectorGeoDetails>, System.Collections.Generic.Dictionary2<Int32,NePTune.Logic.Algorithms.UlInterference.CellMeasurementList>) 
at NePTune.Logic.Algorithms.UlInterference.UlInterferenceDriver.Execute(NePTune.Common.Configuration.GlobalConfiguration, NePTune.Logic.Algorithms.UlInterference.UlInterferenceConfiguration) 
at NePTune.Logic.Algorithms.AlgorithmJobs.UlInterferenceJob.Execute(NePTune.Common.Configuration.GlobalConfiguration, NePTune.Logic.Algorithms.Common.IAlgorithmConfiguration, System.String, System.String, System.String) 
at NePTune.Logic.Algorithms.AlgorithmJobs.UlInterferenceJob.Execute(Quartz.IJobExecutionContext) 
at Quartz.Core.JobRunShell.Run() 
at Quartz.Simpl.SimpleThreadPool+WorkerThread.Run() 
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) 
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) 
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) 
at System.Threading.ThreadHelper.ThreadStart()

1 个答案:

答案 0 :(得分:0)

我在CodePlex(https://sharpmap.codeplex.com/)的SharpMap项目页面上讨论过这个问题,然后他们建议在调用地图之前克隆地图。

在添加“动态图层”然后调用GetMap()之前,我稍微更改了代码以在每次迭代中克隆地图。

这可以防止访问冲突。

在此处查看更多详情: https://sharpmap.codeplex.com/discussions/558218