Splash screen(MetroFramework) is not displaying C#

2019-08-27 14:01发布

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();
    }
}

标签: c# modern-ui
2条回答
放荡不羁爱自由
2楼-- · 2019-08-27 14:40

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.

查看更多
SAY GOODBYE
3楼-- · 2019-08-27 14:51

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.

查看更多
登录 后发表回答