我在窗口服务中使用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()发布于 2014-08-31 07:28:01
我在CodePlex上的CodePlex项目页面(https://sharpmap.codeplex.com/)中讨论了这个问题,在那里,他们建议在调用获取地图之前克隆地图。
在添加“动态层”然后调用GetMap()之前,我稍微修改了代码,以便在每次迭代中复制映射。
这样可以防止访问冲突。
https://stackoverflow.com/questions/25114072
复制相似问题