dotnet / dotnet/wpf

Delay occurs while getting the size from the FormattedText

Open
#6,642 9 comments 0 reactions 0 assignees View on GitHub
Investigate Performance
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

* .NET Core Version: .Net 6.0
* Windows version: Windows11- 22000.675
* Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes
* Is this bug related specifically to tooling in Visual Studio -No



**Problem description:**
Delay Occurs while getting the size from the Formatted Text.

**Expected behavior:**
Delay should not be occured.
**Minimal repro:**
1.Run the sample
2.Click the Initialize Formatted Text button.

Note : Delay occurs, button is in pressed state for a long time.
Please refer the below code snippet and gif file.
```
private void Button_Click(object sender, RoutedEventArgs e)
{

for (int i = 0; i <= 30000; i++)
{
FormattedText text = new FormattedText("Demo", System.Globalization.CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface(FontFamily, new FontStyle(), FontWeights.Normal, FontStretch), 14, Brushes.Black);
Size demo = new Size(text.Width, text.Height);
}
MessageBox.Show("Initialized");
}
```
![ScreenCapture_6-2-2022 4 50 39 PM](https://user-images.githubusercontent.com/92511047/171631346-830650aa-7450-4ae9-a067-270eed92d05e.gif)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.