Hi, i have a problem with showing splash screen while loading.
[STAThread]
public static void Main(string[] args)
{
...
CallMainForm(args);
}
private static void CallMainForm(string[] args = null)
{
SplashScreen splash = new SplashScreen();
splash.Show();
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:
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:
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?