多线程闪屏在C#中?多线程

由网友(你再難遇我)分享简介:我希望有一个启动画面显示,而应用程序加载。我有一个系统托盘控制依赖于它的形式。我想闪屏来显示,而这种形式的负荷,这需要时间一点,因为它的访问Web服务的API来填充一些下拉框。我也希望做一些基本的测试之前加载依赖关系(也就是Web服务是可用的,该配置文件是可读)。由于启动的每个阶段进入,我想更新与进步的启动画面。I...

我希望有一个启动画面显示,而应用程序加载。我有一个系统托盘控制依赖于它的形式。我想闪屏来显示,而这种形式的负荷,这需要时间一点,因为它的访问Web服务的API来填充一些下拉框。我也希望做一些基本的测试之前加载依赖关系(也就是Web服务是可用的,该配置文件是可读)。由于启动的每个阶段进入,我想更新与进步的启动画面。

I want a splash screen to show while the application is loading. I have a form with a system tray control tied to it. I want the splash screen to display while this form loads, which takes a bit of time since it's accessing a web service API to populate some drop-downs. I also want to do some basic testing for dependencies before loading (that is, the web service is available, the configuration file is readable). As each phase of the startup goes, I want to update the splash screen with progress.

我一直在阅读了很多线程,但我迷失在哪里,这应该从控制(在main()方法?)。我也缺少如何 Application.Run()作品,这其中,应该从创建这个线程?现在,如果与系统控制托盘的形式是活的形式,应该溅从那里来?那岂不是不加载,直到形式完成呢?

I have been reading a lot on threading, but I am getting lost on where this should be controlled from (the main() method?). I am also missing how Application.Run() works, is this where the threads for this should be created from? Now, if the form with the system tray control is the "living" form, should the splash come from there? Wouldn't it not load until the form is completed anyway?

我不是在寻找一个code讲义,更多的算法/方法,所以我可以算出这个一劳永逸:)

I'm not looking for a code handout, more of an algorithm/approach so I can figure this out once and for all :)

推荐答案

那么,对于一个的ClickOnce应用程序,我部署在过去,我们使用Microsoft.VisualBasic命名空间来处理启动画面线程。您可以参考和使用Microsoft.VisualBasic程序集从C#.NET 2.0中,它提供了很多很好的服务。

Well, for a ClickOnce app that I deployed in the past, we used the Microsoft.VisualBasic namespace to handle the splash screen threading. You can reference and use the Microsoft.VisualBasic assembly from C# in .NET 2.0 and it provides a lot of nice services.

从Microsoft.VisualBasic.WindowsFormsApplicationBase具备的主要形式继承

重写OnCreateSplashScreen方法,像这样: Have the main form inherit from Microsoft.VisualBasic.WindowsFormsApplicationBase

Override the "OnCreateSplashScreen" method like so:

protected override void OnCreateSplashScreen()
{
    this.SplashScreen = new SplashForm();
    this.SplashScreen.TopMost = true;
}

非常简单,这说明你的SplashForm(你需要创建),而负载是怎么回事,然后自动关闭它曾经的主要形式已完成加载。

Very straightforward, it shows your SplashForm (which you need to create) while loading is going on, then closes it automatically once the main form has completed loading.

这真的让事情变得简单,并且VisualBasic.WindowsFormsApplicationBase当然是深受微软测试,有很多的功能,可以让你的生活中的WinForms轻松了许多,即使在应用程序是100%的C#。

This really makes things simple, and the VisualBasic.WindowsFormsApplicationBase is of course well tested by Microsoft and has a lot of functionality that can make your life a lot easier in Winforms, even in an application that is 100% C#.

在一天结束的时候,这一切都IL和字节code,无论如何,所以为什么不使用它?

At the end of the day, it's all IL and bytecode anyway, so why not use it?

阅读全文

相关推荐

最新文章