dotnet / dotnet/wpf

Multi UI thread visit the ContentPresenter at application startup may deadlock

Open
#6,609 5 comments 1 reaction 0 assignees View on GitHub
Bug
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

* .NET Core Version: All
* Windows version: All
* Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes

**Problem description:**

I start the new UI thread in the constructor in App.xaml.cs

And both my Main UI thread and the new UI thread visit the ContentPresenter properties.

The deadlock was found after running the application thousands of times.

**Actual behavior:**

The main UI thread which thread id is 22436 is waiting the static constructor of FrameworkElementFactory.

![](https://user-images.githubusercontent.com/16054566/169640528-d5972c5c-ae40-4813-a484-f589edb6192b.png)

The new UI thread which thread id is 16100 is waiting the lock which capture by main UI thread.

![](https://user-images.githubusercontent.com/16054566/169640586-81efdacf-045c-4beb-a64f-d3eaec30493c.png)

**Expected behavior:**

It can work well.

**Minimal repro:**

Run my demo thousands of times and you can see that the application is hangs

https://github.com/lindexi/lindexi_gd/tree/de8bdfbf4715c7200631913cecd24749c98228a3/BerehenachearbairGarciwereyer

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.