C#闪屏显示方法最佳实践

发布于 2024-08-10 13:56:23 字数 822 浏览 4 评论 0原文

我通过在运行主窗体之前立即启动一个新线程来显示启动窗体。

在此线程运行的方法中,我使用 Application.Run,​​如下面的选项 1 所示。这是执行此操作的正确方法,还是因为我调用了 Application.Run 两次而有问题在等着我?另一种选择是选项 2,如下所示,我调用 .ShowDialog() 来显示表单。

启动窗体本身会在指定时间后关闭,并在窗体本身内进行控制,并且这两个选项似乎都运行良好。

所以我的问题是:选项 1 和选项 2 哪个更可取?如果您能为其中之一给出具体原因,那就太好了。

谢谢。

主要片段:

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

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

显示初始表单选项 1:

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

显示初始表单选项 2:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

仅一夜美梦 2024-08-17 13:56:23

选项 2 可能会遇到麻烦,因为这样您将使用与 MainForm 相同的 Mesageloop,但来自另一个线程。

选项 1 很好。

Option 2 will probably run into trouble because then you are using the same Mesageloop as the MainForm but from another thread.

Option 1 is fine.

少女净妖师 2024-08-17 13:56:23

我意识到这可能是一个不寻常的观点,但您是否考虑过不使用启动屏幕,而是在“欢迎页面”或“帮助>页面”上显示信息。关于'屏幕?

这样做有几个原因:

  1. 除非您进入多线程,否则如果某些警报/消息框在其顶部弹出,则启动屏幕可能无法正确重新绘制,从而完全否定启动屏幕的好处。

  2. 显示“您已安装插件 x、y 和 z”的启动屏幕在加载该信息之前无法真正说明这一点。加载此信息时,您的应用程序已准备就绪,因此您可以关闭启动屏幕,否则它将妨碍用户。

  3. 如果我移开视线并错过了启动屏幕,我就会错过您告诉我的任何信息。如果“许可证将在 3 天后过期”是该信息的一部分,并且今天是星期五,这意味着我不会意识到星期一我无法使用该应用程序。晦涩难懂,但我已经看到了。

I realize that this may be an unusual viewpoint but have you considered not using a Splash screen and instead showing the information on the 'welcome page' or 'help > about' screen instead?

There are a handful of reasons to do this:

  1. Unless you get into multi-threading, a Splash Screen may not repaint properly if some alert/msgbox pops up over the top of it, negating the benefit of the splash screen entirely.

  2. Splash screens that show 'you have plugins x, y and z' installed can't really tell this until that information has been loaded up. By the time this info is loaded, your app is ready to go, so you'll either close the splash screen or it'll be in the way of the user.

  3. If I look away and miss the splash screen, I'll miss whatever information you're telling me. If 'License expires in 3 days' is part of that information, and today is Friday, that means I won't realise that on Monday, I can't use the app. Obscure, but I've seen it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文