Splash screen(MetroFramework) is not displaying C#

2019-08-27 14:37发布

问题:

I used metro framework for create splash screen, but when i use .Abort() function for thread then the splash screen is not working at all. But if i use .Suspend() it's working but even after the main form load, splash screen is not disposing. Here is the code,

    public Login()
    {
        Thread t = new Thread(new ThreadStart(loading));
        t.Start();
        InitializeComponent();

        for(int i = 0; i <= 1000; i++)
        {
            Thread.Sleep(10);
            t.Abort(); 
        }
    }

     void loading()
    {
        Splash frmsplash = new Splash();Application.Run(frmsplash);

    }

here is splash screen code,

public partial class Splash : MetroFramework.Forms.MetroForm
{
    public Splash()
    {
        InitializeComponent();
    }
}

回答1:

Thread.Abort is raised again and again until it's handled with Thread.ResetAbort... consider using join or interrupt and waiting for the thread to exit.



回答2:

I found a solution but do not know whether it'll work for every one, I just put t.Abort() outside the for loop, it does work for me.



标签: c# modern-ui