加载数据并在此期间显示启动屏幕 [英] Load Data and show a splash screen during that

查看:80
本文介绍了加载数据并在此期间显示启动屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须从db4o数据库中加载一些数据,这在我的应用程序启动时需要1到2秒钟,其余的必须等待,因为首先必须加载所有数据。在自己的线程中执行此操作将意味着其余线程必须等待线程完成。我想做一个启动画面或在数据加载过程中执行一些操作,因为这也需要一个自己的线程,对吗?你会怎么做?

I got to load some data out of a db4o database which takes 1 or 2 seconds at the startup of my app, the rest has to wait because first of all the data has to be loaded. doing this in an own thread would mean that the rest has to wait for the thread-finishing. I'd like to do a splash screen or something during the data is loaded for what also need an own thread, right? how would you do?

我正在使用csharp,.net 3.5和winforms

I'm using csharp, .net 3.5 and winforms

推荐答案

在启动时显示启动画面很容易。在应用程序的Main()方法(位于Program.cs中)中,在Application.Run(...)行之前放置以下内容:

Showing a splash screen at startup is easy to do. In your application's Main() method (in Program.cs), put something like this before the Application.Run(...) line:

SplashForm splashy = new SplashForm();
splashy.Show();
Application.Run(new MainForm(splashy));

修改主表单的代码和构造函数,使其看起来像这样:

Modify the code and constructor for your main form so that it looks something like this:

private SplashForm _splashy;
public MainForm(SplashForm splashy)
{
    _splashy = splashy;
    InitializeComponent();
}

然后在MainForm的Load事件结束时(大概包含数据库代码) ),输入以下代码:

Then at the end of your MainForm's Load event (which presumably contains the database code), put this code:

_splashy.Close();
_splashy.Dispose();

如果您选择使用单独的Thread或BackgroundWorker进行数据库访问,那么您实际上就不会需要启动屏幕非常重要,因为您需要在BackgroundWorker执行其工作时出现的某种进度指示器表格。这样做与我在这里的答案不同。

If you choose to do your database access with a separate Thread or BackgroundWorker, then you don't really need a splash screen so much as you need some sort of progress indicator form that appears while the BackgroundWorker is doing its thing. That would be done differently from my answer here.

这篇关于加载数据并在此期间显示启动屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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