We have several problems with this exception, but I can not find technical documentation about the real cause of the problem, all possible sources of this error and what should be avoided to avoid the exception.
I read the following:
Dispatcher processing is paused to avoid return issues when updating the visual tree.
But I'm not sure what the "visual tree update" means and what causes the dispatch of the message to the dispatcher and reproduces the problem.
The following code example reproduces the problem:
Xaml
<Window x:Class="SuspendedPOF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
Height="350"
Width="525">
<StackPanel>
<Button Content="1" x:Name="Button1" IsVisibleChanged="Button1_OnIsVisibleChanged" />
</StackPanel>
</Window>
C # code
using System.Windows;
namespace SuspendedPOF
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button1_OnIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
MessageBox.Show("Hello");
}
}
}
Calling a MessageBox is not the only one that throws this exception, things like Focus are sometimes also problematic.
Any help would be great.