using System.Threading; using System.Windows.Forms; using System.Drawing; namespace AssistDB { public partial class Splash : Form { public Splash() { InitializeComponent(); } //Delegate for cross thread call to close private delegate void CloseDelegate(); //The type of form to be displayed as the splash screen. private static Splash splashForm; static public void ShowSplashScreen(Point point, int height, int width) { // Make sure it is only launched once. if (splashForm != null) return; splashForm = new Splash(); splashForm.StartPosition = FormStartPosition.Manual; splashForm.Location = new Point(width / 2 - splashForm.Width / 2 + point.X, height / 2 - splashForm.Height / 2 + point.Y); ; Thread thread = new Thread(new ThreadStart(Splash.ShowForm)); thread.IsBackground = true; thread.SetApartmentState(ApartmentState.STA); thread.Start(); } static private void ShowForm() { if (splashForm != null) Application.Run(splashForm); } static public void CloseForm() { Thread.Sleep(20); splashForm?.Invoke(new CloseDelegate(Splash.CloseFormInternal)); } static private void CloseFormInternal() { if (splashForm != null) { splashForm.Close(); splashForm = null; }; } } }