WPF screen saver before windows loads

I have an application that consumes a lot of time when loading a window. In the Window_load event, I read the status and name of some controls from the database. I want to make a splash screen that will end after the window has fully loaded.

I tried with this example http://www.codeproject.com/KB/dialog/wpf_animated_text_splash.aspx , but the splash screen closes before the main window is fully loaded and my mainwindow appears in white and is not fully loaded.

I'm new to wpf and I don't know how I can get a splash screen that stays on the screen until the main window loads completely.

Please give me an example.

My screensaver code:

public partial class SplashWindow : Window
    {
        Thread loadingThread;
        Storyboard Showboard;
        Storyboard Hideboard;
        private delegate void ShowDelegate(string txt);
        private delegate void HideDelegate();
        ShowDelegate showDelegate;
        HideDelegate hideDelegate;

        public SplashWindow()
        {
            InitializeComponent();
            showDelegate = new ShowDelegate(this.showText);
            hideDelegate = new HideDelegate(this.hideText);
            Showboard = this.Resources["showStoryBoard"] as Storyboard;
            Hideboard = this.Resources["HideStoryBoard"] as Storyboard;

        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            loadingThread = new Thread(load);
            loadingThread.Start();
        }
        private void load()
        {
            Thread.Sleep(6000);

            this.Dispatcher.Invoke(showDelegate, "first data to loading");
            Thread.Sleep(6000);
            //load data 
            this.Dispatcher.Invoke(hideDelegate);

            Thread.Sleep(6000);
            this.Dispatcher.Invoke(showDelegate, "second data loading");
            Thread.Sleep(6000);
            //load data
            this.Dispatcher.Invoke(hideDelegate);


            Thread.Sleep(6000);
            this.Dispatcher.Invoke(showDelegate, "last data loading");
            Thread.Sleep(6000);
            //load data 
            this.Dispatcher.Invoke(hideDelegate);



            //close the window
            Thread.Sleep(6000);
            this.Dispatcher.Invoke(DispatcherPriority.Normal,(Action)delegate() { Close(); });
        }
        private void showText(string txt)
        {
            txtLoading.Text = txt;
            BeginStoryboard(Showboard);
        }
        private void hideText()
        {
            BeginStoryboard(Hideboard);
        }

    }

And I will call this splash screen in my MainWindow constructor:

new SplashWindow().ShowDialog();

MainWindow Load , Splash , .

!

+3
4

SplashScreen, Show(false), , . Close(), .

, SplashScreen . , , .

:

static class Entry
{
    static void Main(string[] args)
    {
        var splashScreen = new SplashScreen("path/to/your/image.png");
        splashScreen.Show(false);

        InitializeLogging();
        InitializeServices();
        InitializeUserInterface();
        InitializeWhateverElseYouNeed();

        splashScreen.Close(TimeSpan.FromSeconds(1));
    }
}
+21

( ..)

SplashScreen:

1. .NET.

.NET. . .

2. .NET.

, . , 1 ( WPF), . ( ), .

+4

- - Build Action "SplashScreen". . (VS2008 sp1 ).

, ( , ), . , SplashScreen, .

+1

Perhaps because your data loading is complete, but your UI thread has not yet completed displaying. Make sure your user interface is fully displayed before closing the burst.

See links below.

http://www.codeproject.com/KB/WPF/WPFsplashscreen.aspx

http://www.japf.fr/2009/10/measure-rendering-time-in-a-wpf-application/

0
source

All Articles