【发布时间】:2011-06-10 15:03:46
【问题描述】:
用例:我正在使用 WPF 在 Web 上下文中动态覆盖图像上的文本。
解决方案:
我正在使用来自DrawingVisual 的DrawingContext(包装在using 语句中)来绘制原始位图和覆盖文本。
问题:在几千个请求之后,[DrawingVisual].RenderOpen() 方法开始拒绝执行并抛出以下异常:
The system cannot find the file specified System.ComponentModel.Win32Exception UInt16 RegisterClassEx(WNDCLASSEX_D) at MS.Win32.UnsafeNativeMethods.RegisterClassEx(WNDCLASSEX_D wc_d)
at MS.Win32.HwndWrapper..ctor(Int32 classStyle, Int32 style, Int32 exStyle, Int32 x, Int32 y, Int32 width, Int32 height, String name, IntPtr parent, HwndWrapperHook[] hooks)
at System.Windows.Media.MediaContextNotificationWindow..ctor(MediaContext ownerMediaContext)
at System.Windows.Media.MediaContext..ctor(Dispatcher dispatcher)
at System.Windows.Media.MediaContext.From(Dispatcher dispatcher)
at System.Windows.Media.Visual.VerifyAPIReadWrite()
at System.Windows.Media.DrawingVisual.RenderOpen()
at ...
临时修复:解决此问题的唯一方法是回收服务器上的 IIS 应用程序池,从而将问题修复几个小时。
问题:有人知道这个问题的原因(泄漏、线程、非托管代码等)吗?有没有其他方法可以在图像上获取文本以避免绘图视觉?也许将几何图形写入位图并直接覆盖位图?
【问题讨论】:
-
你能分享一下你是如何获得 DrawingContext 和 DrawingVisual 的代码 sn-p 吗?为什么不直接回收 DrawingVisual?您是否允许 Dispatcher 抽水?
-
我知道这是一个老问题,但是进程是否泄漏内存或句柄?似乎挂起转储有助于找到问题的根源?
标签: .net wpf iis rendering system.windows.media