Click here to Skip to main content
15,875,568 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, i have a problem with showing splash screen while loading.
C#
[STAThread]
public static void Main(string[] args)
{
	...
	CallMainForm(args);
}
private static void CallMainForm(string[] args = null)
{
    SplashScreen splash = new SplashScreen();
    splash.Show();
	//loading and other stuff
	MainWindow mainWindow = new MainWindow(args);
    splash.RequestClose();
    mainWindow.Show();
	while (mainWindow.CanExit == false)
        DoEvents();
}

public static void DoEvents()
{
    if (Application.Current != null)
        Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new ThreadStart(delegate { }));
}

There is CanClose property, that determines, if splash screen can be closed and also prevents alt+f4 click on splash screen window:
splash screen:
C#
public void RequestClose()
{
    this.CanClose = true;
    this.Close();
}
public bool CanClose { get; set; }
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
    if (!CanClose)
        e.Cancel = true;
}

and in constructor of splash screen i launch label color changing animation:
C#
public SplashScreen()
{
    InitializeComponent();
    CanClose = false;
    StartAnimation();
}

when i launch application, the animation of splash screen not working and splash window freezes.
any ideas how to fix this?
Posted
Comments
Sergey Alexandrovich Kryukov 21-Mar-15 22:41pm    
It cannot be fixed, the whole idea is so-oooo wrong. First of all, why do you think that you really can do something useful during your animation? Let's say, you can see that it takes so much time to initialize you main window before you can show it. But can you expect that the time delay before the user can see the animation will be considerably shorter? I'm not saying that flash screens are totally useless, I'm just trying to give an idea on what to start with...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900