0

I have a splash screen in my winforms application which occasionally throws exception Thread was being Aborted when I try to abort it, if I don't abort the thread, the splash screen doesn't go away, can someone help with a better way to get this done?

Here's my code:

  public FrmMainForm()
    {
        Thread thread = new Thread(new ThreadStart(Loading));
        thread.Start();
        InitializeComponent();
        for (int i = 0; i <= 500; i++)
            Thread.Sleep(4);
        try
        {
            thread.Abort();
        }
        catch (ThreadAbortException)
        {
            Thread.ResetAbort();
        }
    }
    void Loading()
    {
        try
        {
            //FrmSplashScreen form = new FrmSplashScreen();
            Application.Run(new FrmSplashScreen());
        }
        catch
        {

        };
    }
  • [Splash Screen waiting until thread finishes](https://stackoverflow.com/a/393870/7444103) – Jimi Jul 15 '20 at 06:52
  • 2
    **Do not** (i repeat) **do not abort threads**... There is no good reason for it, and you are most definitly doing the wrong thing (unless you completely know what its doing, the ramifications, and you are going to tear down the app domain). – TheGeneral Jul 15 '20 at 06:58
  • @PeterDuniho, there is [this answer](https://stackoverflow.com/a/32469582/1997232) in duplicate, which does it exactly as OP. – Sinatr Jul 15 '20 at 07:06

0 Answers0