0

How to properly start a new form (which only shows logo.jpg) as a new thread and kill in a different (no time limit) moment? I have a working solution like below, but I guess aborting is not the best option - sometimes form stays after closing the main program, until mouse moves over. Please advise how to make it better ...

//field declarations:
        frmLogo frmStart = new frmLogo();
        private Thread startLogoThread;

public main()
        {
            this.startLogoThread = new Thread(new ThreadStart(this.frmLogoStart));
            this.startLogoThread.Start();
            InitializeComponent();
        }

        private void frmLogoStart()
        {
            System.Windows.Forms.Application.Run(frmStart);
        }

 private void mainForm_Load(object sender, EventArgs e)
        {
            // loading of SQL  
            // this is a point where I want to kill the logo thread
            this.startLogoThread.Abort();
            this.BringToFront();
        }
mallorn
  • 735
  • 1
  • 6
  • 10
  • I suggest you read this: https://stackoverflow.com/questions/7955663/how-to-build-splash-screen-in-windows-forms-application – o_weisman Oct 24 '17 at 06:33
  • Killing/aborting a thread (which is always bad) has no effect on the window objects that thread owns, other than to ensure that they no longer receive messages (which is also bad). Instead, you should run a proper message pump and close the window or use `Application.ExitThread()` (depending on how you called `Application.Run()` to terminate the thread. See [this answer](https://stackoverflow.com/a/4994912) in the marked duplicate for an example. – Peter Duniho Oct 24 '17 at 06:36
  • Just close the `frmStart` and the Thread will come to a peaceful end. When you need to initiate the Close from the mainForm then use `frmStart.Invoke()` – H H Oct 24 '17 at 06:39
  • Re the duplicate: look at the answer from Nofsinger. – H H Oct 24 '17 at 06:39

0 Answers0