xamarin/Xamarin.Forms

[Bug] Using fonts from a non-UI thread results in exception with HRESULT 0x8001010E (RPC_R_WRONG_THREAD) on UWP

开放

#8,840 创建于 2019年12月10日

 (7 条评论) (1 个反应) (0 位负责人)C# (1,926 个派生)batch import
e/4 :clock4:help wantedi/highinactivep/UWPt/bug :bug:up-for-grabs

仓库指标

星标
 (5,644 个星标)
PR 合并指标
 (30 天内没有已合并 PR)

描述

Description

Using fonts from a non-UI thread, even when the font is not being used in a page's UI hierarchy, results in an exception with HRESULT 0x8001010E (RPC_R_WRONG_THREAD) on UWP.

This prevents pages being prepared away from the UI thread before they are actually required, meaning that an obvious performance improvement technique cannot be used on UWP if fonts are used at all (the same problem happens if XAML is used as well).

Steps to Reproduce

  1. Add a Button to a page, with the Button defined as follows:

                     new Button
                     {
                         Text = "Use a font on a non-UI thread",
                         Command = new Command(() =>
                         {
                             Task.Run(() =>
                             {
                                 Xamarin.Forms.Label label = new Xamarin.Forms.Label
                                 {
                                     Text = "Hello",
                                     FontAttributes = FontAttributes.Italic
                                 };
                             });
                         })
                     }
    
  2. Run the code and press the Button

  3. The exception occurs, even though the View with the FontAttribute being set is not hooked into the UI hierarchy.

Expected Behavior

No exception. Font-related properties should be set as per the code.

Actual Behavior

Exception with HRESULT 0x8001010E (RPC_R_WRONG_THREAD)

Basic Information

  • Version with issue: 4.3.0.991211 (but this has been a problem for a long time)
  • IDE: VS2019
  • Platform Target Frameworks:
    • UWP: 18362

贡献者指南