Using a BackgroundVisualHost causes a crash in WPF (example repo available)
From @adscott1982 on Tuesday, December 3, 2019 5:04:20 PM
Showing / hiding UI on a non-main thread dispatcher will cause WPF to crash.
This problem is present on .NET Core 3.0, Framework 4.8, 4.7.2 and 4.7.0 and perhaps others.
Using the technique in the following blog post used to work, but will now eventually cause a crash in WPF:
http://gettinggui.com/creating-a-busy-indicator-in-a-separate-thread-in-wpf/
This issue has only been seen since around September 2019.
A repo demonstrating the issue is here, and will usually cause the issue within a couple of minutes:
https://github.com/adscott1982/BackgroundUIThreadError
My system is:
Windows 10 Professional 1909 Visual Studio 2019 Professional Nvidia Quadro P400
There are various different exception messages that will be shown when the issue presents itself. I will gather up as many as I can and attach them as text files.
Catastrophic failure.txt internal error in the dot net runtime.txt render thread failure.txt missing end command.txt
Copied from original issue: dotnet/core#3948
We are hitting this as well. We have to use the BackgroundVisualHost because the main dispatcher must create controls on screen and that can take quite a while of course. Without something like the approach demonstrated, WPF apps can't appear responsive. We are on .NET Core 3.1 at present but we also experienced it in Framework 4.7.2 and 4.8.
Hi. We're also experiencing this issue. Has anyone managed to found a workaround? @AdamCaviness?
As a quick temporary fix we replaced this control with DXSpashScreen from Devexpress which our app is based on, it covers our use cases.
@scalablecory - I tried to replicate the issue and I can see the repro app crashes as soon as click the close button, is it the original issue?
Can you please provide the repro steps so that I can be assure I am not missing anything.
@adscott1982
@Kuldeep-MS note the original issue was created by @adscott1982
UPDATE- I have taken a look at the code of repro app and found that if we simply add null check for Application.Current it resolves the issue
see the code below:
this.decoratorTimers.Add(new Timer(o =>
{
Application.Current?.Dispatcher?.Invoke(
() =>
{
this.Decorator4.IsBusyIndicatorShowing = !this.Decorator4.IsBusyIndicatorShowing;
});
},
null,
(int)(this.random.NextDouble() * 100) + 100,
(int)(this.random.NextDouble() * 100) + 100));
@adscott1982 - Let me know if I missed anything too look at?
Hi @Kuldeep-MS - it has been a very long time. I believe the issue you are seeing is unrelated to the issue that was being exhibited originally by the test app. The issue would occur after a few minutes of running the app, not while closing the app.
If you read the original issue you can see. If you are unable to reproduce the issue with the app, then the issue must already be resolved somehow, or not present on your workstation with your display adapter / drivers.
@adscott1982 - Thanks for your reply. We are closing the issue as it is not reproducible. We can reopen the issue when repro app is available.