闪屏显示方法的最佳实践C# [英] Splash screen display method best practice C#

查看:98
本文介绍了闪屏显示方法的最佳实践C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我显示飞溅形式,立即运行我的主要形式开始之前,一个新的线程。

在由这个线程运行的方法,我使用Application.Run,​​如下面的选项1。这是这样做的正确的方式,或正在等着我有问题,我becaue呼吁Application.Run两次?另一种方法是选择2,也显示如下,我称之为.ShowDialog()来显示表单。

飞溅的形式本身在指定的时间后关闭,形式本身的控制,这两个选项似乎很好地工作。

所以我的问题是:这是preferred - 选项1或选项2?如果你能给出具体的原因,一个或另一个,将是巨大的。

感谢。

主要的段:

  //运行启动画面线程。
螺纹飞溅=新主题(新的ThreadStart(ShowSplash));
splash.Start();//运行主应用程序。
Application.Run(新的MainForm());

显示启动表格选项1:

 静态无效ShowSplash()
    {
        Application.Run(新SplashForm());
    }

显示启动表格选项2:

 静态无效ShowSplash()
    {
        使用(SplashForm飞溅=新SplashForm())
        {
            splash.ShowDialog();
        }
    }


解决方案

<一个href=\"http://stackoverflow.com/questions/392864/c-splash-screen-problem\">http://stackoverflow.com/questions/392864/c-splash-screen-problem

看到最受好评的答案

I am showing a splash form by starting a new thread immediately before running my main form.

In the method that is run by this thread, I am using Application.Run as shown in Option 1 below. Is this a correct way of doing this, or are there problems waiting for me becaue I have called Application.Run twice? An alternative is Option 2, also shown below where I call .ShowDialog() to display the form.

The splash form itself closes after a specified time, controlled within the form itself, and both options appear to work well.

So my question is: Which is preferred - Option 1 or Option 2? If you could give specific reasons for one or the other that would be great.

Thanks.

Snippet of Main:

// Run splash screen thread.
Thread splash = new Thread(new ThreadStart(ShowSplash));
splash.Start();

// Run main application.
Application.Run(new MainForm());

Show splash form option 1:

    static void ShowSplash()
    {
        Application.Run(new SplashForm());
    }

Show splash form option 2:

    static void ShowSplash()
    {
        using (SplashForm splash = new SplashForm())
        {
            splash.ShowDialog();
        }
    }

解决方案

http://stackoverflow.com/questions/392864/c-splash-screen-problem

see most rated answer

这篇关于闪屏显示方法的最佳实践C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆