最近遇到一個問題,窗體在Loaded同時Resize會出現黑屏或者直接崩潰, 調查發現是WPF后端的Render線程渲染UI到DirectX時崩潰。
硬件環境:WES7 + .Net4.0
[關于WPF有2個線程的解釋如下:](https://msdn.microsoft.com/zh-cn/library/ms741870(v=vs.90).aspx)
*WPF 應用程序從兩個線程開始:一個用于處理呈現,一個用于管理 UI。呈現線程有效地隱藏在后臺運行,而 UI 線程則接收輸入、處理事件、繪制屏幕以及運行應用程序代碼。*
遇到的這個問題就是用于處理呈現的線程掛了,異常如下:
Exception from HRESULT: 0x88980406
Stack Trace:
0000000021a4d8d8 000007fef7a66869 [HelperMethodFrame: 0000000021a4d8d8]
0000000021a4da20 000007fee485ae0f System.Windows.Media.Composition.DUCE+Channel.SyncFlush()***WARNING: Unable to verify checksum for PresentationCore.ni.dll
0000000021a4dae0 000007fee3e95615 System.Windows.Interop.HwndTarget.UpdateWindowSettings(Boolean, System.Nullable`1<ChannelSet>)
0000000021a4dd10 000007fee3eabfec System.Windows.Interop.HwndTarget.UpdateWindowSettings(Boolean)
0000000021a4dd80 000007fee3eabd0e System.Windows.Interop.HwndTarget.UpdateWindowPos(IntPtr)
0000000021a4dee0 000007fee3e95fd7 System.Windows.Interop.HwndTarget.HandleMessage(MS.Internal.Interop.WindowMessage, IntPtr, IntPtr)
0000000021a4e070 000007fee3e93d14 System.Windows.Interop.HwndSource.HwndTargetFilterMessage(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
0000000021a4e0c0 000007fee4b2b450 MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
**[微軟分析的原因及建議方案](http://blogs.msdn.com/b/dsui_team/archive/2013/11/18/wpf-render-thread-failures.aspx)**
1. Update your video drivers, and/or try different video hardware in the problem machine(s). 【試過560、660、770、970顯卡都不會解決問題, 試過320.18, 320.49, 353.30等驅動也都不會解決問題】
2. Disable Hardware rendering. As a quick test, you can use the DisableHWAcceleration registry value discussed here. You would set the value to 1 in order to disable WPF's hardware rendering pipeline. Note that this affects all WPF applications running in that user's session, so be advised you might be impacting more than one application. There are other options for disabling hardware acceleration at a more granular level. Starting in .Net 3.5, you can disable it programmatically on a per-window basis by using the HwndTarget.RenderMode property. Starting in .Net 4.0, you can disable it programmatically on a per-process basis by using the RenderOptions.ProcessRenderMode property. 【更改注冊表不會解決問題】
3. Upgrade to the latest version and service pack level of the .Net Framework available for your target platform. 【升級到Net 4.5后,問題解決。降級到4.0后,又出現】
4. Disable the use of Windows.AllowsTransparency and Popup.AllowsTransparency in your application.【包裝的應用窗體的AllowsTransparency為False】
5. If you are on Windows XP or Windows 2003, test on a newer operating system, and upgrade if possible.【沒有測試,升級OS不太可能】
6. If System.OutOfMemoryExceptions are being reported, then monitor the process's memory usage in Performance Monitor; particularly the Process\Virtual Bytes, Process\Private Bytes, and .NET CLR Memory\# Bytes in All Heaps counters. Also monitor the User Objects and GDI Objects for the process in Windows Task Manager. If you can determine that a specific resource is being exhausted, then troubleshoot the application to fix whatever is causing that resource consumption. Ultimately that should resolve the System.OutOfMemoryException.【查看內存和句柄等,沒有內存泄露】
**[微軟說明](https://connect.microsoft.com/VisualStudio/feedback/details/674249/wpf-renderer-thread-exited-with-codes-0x88980406-0x88980403)**[](https://connect.microsoft.com/VisualStudio/feedback/details/674249/wpf-renderer-thread-exited-with-codes-0x88980406-0x88980403)**[Net 4.5](https://connect.microsoft.com/VisualStudio/feedback/details/674249/wpf-renderer-thread-exited-with-codes-0x88980406-0x88980403)[解決此問題:](https://connect.microsoft.com/VisualStudio/feedback/details/674249/wpf-renderer-thread-exited-with-codes-0x88980406-0x88980403)**


- 前言
- win32與WPF的混合編程
- WPF: 一個可以用StoryBoard動態改變Grid行寬/列高的類
- MFC中調用WPF教程
- Expression Blend操作: 使用behavior來控制Storyboard
- WPF DatePicker 的textbox的焦點
- WPF 使用MultiBinding ,TwoWay ,ValidationRule ,需要注意的事項
- WPF TreeView 后臺C#選中指定的Item, 需要遍歷
- WPF GridViewColumn Sort DataTemplate
- DataGridColum的bug
- WPF Get Multibinding Expression, Update Source,
- WPF 后臺觸發 Validate UI‘s Element
- WPF ValidationRule 觸發ErrorTemplate 的注意事項
- WPF DelegateCommand CanExecute
- WPF TextBox PreviewTextInput handle IME (chinese)
- No overload for &#39;OnStartup&#39; matches delegate &#39;System.Windows.StartupEventHandler&#39;
- WPF error: does not contain a static &#39;Main&#39; method suitable for an entry point
- WPF GridView中的CellTemplate失效的原因
- DataGrid 顯示選中的item
- 如何得到WPF中控件綁定的EventTrigger
- 選中DataGrid的Cell而不是row
- ContextMenu的自定義
- 輸入框只能輸入英文
- TextBox的OnTextboxChanged事件里對Text重新賦值帶中文, 導致崩潰
- DataGrid當列寬超出當前寬度時,沒有數據也恒有滾動條
- wpf如何獲取control template里的元素
- Set connectionId threw an exception.
- WPF中Visible設為Collapse時,VisualTreeHelper.GetChildrenCount為0
- XAML 編碼規范 (思考)
- 如何為現有控件的DependencyProperty添加Value Changed事件?
- TreeView滾動TreeViewItem
- 為BindingList添加Sort
- WPF Background的設置有坑
- 自定義Panel中添加依賴屬性需要注意的問題
- TextBlock截斷字符顯示為....
- DataGrid 支持字符截斷顯示
- TreeView控件實踐
- WPF如何更改系統控件的默認高亮顏色 (Highlight brush)
- ViewModel中C# Property自動添加OnPropertyChanged處理的小工具, 以及相應Python知識點
- WPF中Xaml編譯正常而Designer Time時出錯的解決辦法
- 關于Snoop的用法
- wpf中為DataGrid添加checkbox支持多選全選
- WPF中DataGrid控件的過濾(Filter)性能分析及優化
- wpf控件提示Value ‘’ can not convert
- DropShadowEffect導致下拉框控件抖動
- 再論WPF中的UseLayoutRounding和SnapsToDevicePixels
- WPF案例:如何設計歷史記錄查看UI
- WPF案例:如何設計搜索框(自定義控件的原則和方法)
- WPF基本概念入門
- WPF開發中Designer和碼農之間的合作
- 聊聊WPF中的Dispatcher
- 聊聊WPF中字體的設置
- Bug:DataGridCell的顯示不完整
- WPF中ToolTip的自定義
- WPF中ItemsControl綁定到Google ProtocolBuffer的結構體時的性能問題
- TreeView的性能問題
- Xaml中string(字符串)常量的定義以及空格的處理
- 依賴屬性
- WPF中的CheckBox的_ (underscore / 下劃線)丟失
- WPF錯誤:必須使“Property”具有非 null 值。
- WPF中ItemsControl應用虛擬化時找到子元素的方法
- WPF毫秒級桌面時鐘的實現-C#中Hook(鉤子)的應用
- KB2464222導致IsNonIdempotentProperty方法找不見
- WPF中PreviewMouseDownEvent的系統處理:TabItem的PreviewMouseDown 事件彈框后不切換的問題調查
- WPF文字渲染相關的問題及解決
- wpf中的默認右鍵菜單中的復制、粘貼、剪貼等沒有本地化的解決方案
- WPF內部DeliverEvent讀鎖和PrivateAddListener寫鎖導致死鎖
- Windbg調試WPF的依賴屬性
- WPF 后臺Render線程崩潰, Exception from HRESULT: 0x88980406
- WPF中DependencyObject與DependencyProperty的源碼簡單剖析
- 禁用WPF中DataGrid默認的鼠標左鍵拖動多選行的效果
- wpf工程中在Xaml文件下添加多個cs文件
- ScrollViewer滾動到底來觸發加載數據的Behavior