I have to do a lot of operations when I start my application. I have to show a splash screen with loaded percentage. The idea is the first time to record the time necessary to load, then serialize it with other data. The following times I have all what's necessary to show the percentage on the splash screen.
At the beginning therefore I create a splashscreen window with some info
var bmpSplash = new BitmapImage(new Uri(@"pack://application:,,,/Resources/Images/splashScreen.png", UriKind.RelativeOrAbsolute));
splashScreen = new EmptyWindow.EmptyWindow(bmpSplash) { SizeToContent = SizeToContent.Manual, Width = 612, Height = 378, Background = Brushes.Transparent, WindowStyle = WindowStyle.None, AllowsTransparency = true, Topmost = true };
...
var tbPercetage = new TextBlock() { Text="AAAA", FontSize = 16, Width = splashScreen.Width, TextAlignment = TextAlignment.Left, Height = 50, VerticalAlignment = VerticalAlignment.Bottom, Margin = new Thickness(150, 0, 0, 50) };
...
splashScreen.grdMain.Children.Add(otbVersion4);
splashScreen.Show();
then I create a Dispatcher timer which has to update the percentage:
DispatcherTimer tmrSplashPercentage = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(125) };
tmrSplashPercentage.Tick += (sender2, args) =>
{
((TextBlock)splashScreen.grdMain.Children[3]).Dispatcher.Invoke(() => ((TextBlock)splashScreen.grdMain.Children[3]).Text= DateTime.Now.Ticks.ToString(), DispatcherPriority.Background);
};<---- it is the 4th children
Dispatcher.CurrentDispatcher.Invoke(new Action(() => { tmrSplashPercentage.Start(); }));
I use the Invoke because I have seen that by doing this I can force update. But if I put a breakpoint in the timer tick I have seen that it is not fired until all the load procedure is done. So either it doesn't start or the tick event is not fired.
Thank you for any help! Patrick
---ADD---
Sorry forgot to say that the events take place in the MainView() and then continues in the WindowViewBase_Loaded event.
I know that I might now use a timer but put several updates after each step but that wouldn't make it precise....