WPF界面不響應任何交互

Software Rendering Usage in WPF


  • wpf界面在一定情況下,會不響應任何交互,整個窗口圖片一樣,其實,wpf有兩種方式渲染界面,硬件渲染、軟件渲染。以下爲找到的相關資料,下方鏈接爲文章原地址。

https://blogs.msdn.microsoft.com/jgoldb/2010/06/22/software-rendering-usage-in-wpf/

  • WPF默認使用GPU渲染界面,即硬件渲染。

  • 大多數情況下,使用硬件渲染都能獲得更好的性能。其他一些情況下,軟件方式渲染可能更快。

  • WPF優先使用硬件渲染,但是在特定條件下,會使用軟件渲染方式,此時界面會表現爲未響應狀態

  • 以下幾種情況下,wpf會使用軟件渲染的方式

    • 很老的顯卡,2004年11月之前的硬件

    • WPF檢測到名爲“Tier 0”的顯卡,“Tier 0”表示不支持硬件渲染,或者DirectX版本在7.0以前

    • 窗口的渲染尺寸大於顯卡的渲染的最大尺寸,常發生在,窗口跨多個屏幕顯示的情況

    • 在遠程桌面的方式下運行程序。

      Until NET 3.5 SP1 and earlier, remoting between Vista to Vista with DWM on, leveraged a custom WPF primitive remoting protocol. In all other scenarios content was remoted as bitmaps. Starting with the release of NET 3.5 SP1 (including NET 4), WPF renders the application content using a software rasterizer on the server and then remotes the content as bitmaps in all cases.

    • 虛擬機中運行程序。WPF會先嚐試用硬件渲染界面,但是在有些虛擬機中,運行異常。用戶需要強制指定軟件方式渲染,來避免運行異常,使用如下代碼來指定軟件方式渲染:

          RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;       // Force Software rendering per Process – New in NET4
          hwndTarget.RenderMode = RenderMode.SoftwareOnly;        // Force Software rendering per Window– Introduced in Net 3.5 SP1
      
      
    • 在註冊表中指定了,不使用硬件方式渲染。

      (HKEY_CURRENT_USER\Software\Microsoft\Avalon.Graphics]
      “DisableHWAcceleration”=dword:00000000 )

      注意: 該鍵會影響所有wfp界面,僅在測試的時候使用

    • Application uses legacy style bitmap effects.Note: these are obsolete in NET4.

    • Application printed content.

    • Rasterized content that uses RenderTargetBitmap

    • Tiled content that uses TileBrush

    • Use of too many light objects in your 3D scene. Read more here.

    • Layered windows (only on XP SP2/W2k3 or before that do not have Hotfix installed.

    • Graphics hardware failures, such as “Out Of Video Memory” (OOVM).

    • WPF try to free up video memory and stay in HW rendering but it may not always work and WPF will fall to Software

  • 可以使用WPF Performance Profiling Tools中的Perforator來檢測程序使用那種方式渲染。具體看這裏

Option Description
Draw software rendering with purple tint Draws all areas rendered by using the software rendering pipeline with a purple tint. This includes software render targets, software 3D content, and per-primitive software fallback.
Draw software rendered bitmap effects with red tint Draws legacy software rendered bitmap effects with red tint.
  • 如何在代碼中檢測渲染方式?
    • 檢查 RenderingCapability.Tier,同時也可以監聽Tier變化事件。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章