I have a code part where I call some XML data from a server. Sometimes there is an error with the network or the server itself. So I need some error handling. For that I installed the AwesomeFonts.WPF and created a simple
<StackPanel Name="ErrorPanel" Height="200" Width="300" Visibility="Hidden" Canvas.Top="440" Canvas.Left="810" Panel.ZIndex="9999">
<fa:ImageAwesome Icon="Spinner" Spin="True" Height="100" Width="100" />
<TextBlock Text="data loading..." />
</StackPanel>
That should show a loading animation of a spinning icon. Now I wanted to do something like
ErrorPanel.Visibility = Visibility.Visible;
mainPznItem.SubPzns = Communication.GetProductList(tempPznList);
ErrorPanel.Visibility = Visibility.Hidden;
Now I know of the dispatching problems of WPF and tried already something like this
Application.Current.Dispatcher.Invoke(() => { ErrorPanel.Visibility = Visibility.Visible; });
or something like this
Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new
ThreadStart(delegate
{
ErrorPanel.Visibility = Visibility.Visible;
}));
On this one I really get the Panel visible, but the animation stopped.
And I wanted to let a timer run, so that I can shorten the timeout of the server. I wanted to do something more like:
1. Show animation
2. Start timer
3. Call the server
4. Count to 10
5. If I dont get the answer until 10, then show an error message, else show the result
6. Hide the waiting animation.
Has someone an idea how to achieve this?