提高感知的WPF应用程序的启动时间应用程序、时间、WPF

2023-09-03 06:37:39 作者:Hold on

我有一个WPF数据库浏览器应用程序:它包含了数据网格显示从SQLite数据库提取数据的用户控件一个简单的主窗口。 的问题是,这种应用需要6秒开始,直到它是可用的。

I have a WPF database viewer application: It's a simple main window containing a user control with a data grid showing the data extracted from an SQLite database. The problem is that this application takes 6 seconds to start until it is usable.

我试图构建用户控件(和做所有的数据加载)在主窗口的构造函数: 启动屏幕将显示5秒这种方式,再其次是空的主窗口1,直到应用程序就可以使用了。 用户说,时间过久,直到东西(视觉)发生。

I tried building the user control (and doing all the data loading) in the constructor of the main window: The splash screen will be shown 5s this way, then followed by 1s of empty main window until the application is ready to be used. Users said that it takes too long until something (visually) happens.

我然后移动用户控件创建(和数据加载)到主窗口的Loaded事件处理: 启动屏幕将显示3秒,然后直到应用程序已经准备好空的主窗口中三分球。 用户说,这是更好,但不喜欢的事实,一个半完成的主窗口显示在禁用状态了这么久。

I then moved the user control creation (and data loading) into the Loaded event handler of the main window: The splash screen will be shown 3s, followed by 3s of empty main window until the application is ready. Users said that it is "better", but don't like the fact that a half finished main window is shown in disabled state for so long.

有一些一般性的建议可以找到有关感知应用程序加载的时间,还是有对这种情况如何改进任何其他建议? 相信理想地,直到数据被加载在主窗口将被示出尽可能快地,连同一些小时玻璃或旋转器。但我不能只是移动用户控件创建成一个后台工作,因为这会在错误的线程上完成。

Is there some general advice to be found about perceived application load time or are there any other recommendations about how this situation can be improved? I believe ideally the main window would be shown as fast as possible, along with some hour glass or spinner until the data is loaded. But then I cannot just move the user control creation into a background worker as this would be done on the wrong thread.

没有任何人有任何建议,这个问题?

Does anybody have any suggestions to this problem?

编辑: 需要注意的是,现在我刚刚分配了一个LINQ到EF查询作为网格数据源。 一个可能的改善可能是数据加载到后台中的数据表,并为其分配只有一次加载中...

Note that right now I've just assigned a LINQ-to-EF query as the grid data source. One possible improvement may be to load this data into a data table in background and assign it only once loaded...

EDIT2: 我使用的是.NET 4 System.Data.SQLite和EF4加载数据。有更多或更少的4000行和30列。

I'm using .net 4 with System.Data.SQLite and EF4 to load the data. There are more or less 4000 rows and 30 columns.

推荐答案

装入的数据同步。 present一些好听的图形用户界面,同时加载的用户。下面code可以帮助你这样的:

Load your data asynchronous. Present something nice on the GUI for the user while loading. The following code can help you with this:

BackgroundWorker bgWorker = new BackgroundWorker() { WorkerReportsProgress=true};  
bgWorker.DoWork += (s, e) => {      
    // Load here your file/s      
    // Use bgWorker.ReportProgress(); to report the current progress  
};  
bgWorker.ProgressChanged+=(s,e)=>{      
    // Here you will be informed about progress and here it is save to change/show progress. 
    // You can access from here savely a ProgressBars or another control.  
};  
bgWorker.RunWorkerCompleted += (s, e) => {      
// Here you will be informed if the job is done. 
// Use this event to unlock your gui 
};  
bgWorker.RunWorkerAsync();  

该应用程序是不是更快,但它似乎更快,因为图形用户界面是立即可见,反应灵敏。也许你还可以显示用户加载的数据的一部分,同时装载其余部分。使用 ProgressChanged -event这样做。

The app is not faster but it seems to be much faster because the GUI is immediately visible and responsive. Maybe you also can show the user a part of the loaded data while loading the rest. Use the ProgressChanged-event for doing this.

更新

我不知道如果我理解你的问题的权利。如果你的问题不是数据需要被加载的时候,那么什么是奇数在您的应用程序。 WPF是国际海事组织非常快。控制创造并不需要花费很多时间。我想象大得多列出你提到的几毫秒。

I'm not sure if I understand your problem right. If your problem is not the time data needs to be loaded, then something is odd in your application. WPF is IMO very fast. Control-creation does not takes a lot of time. I visualize much bigger lists as you mention in some milliseconds.

尝试一下,如果你有东西在你的UI阻碍DataGrid的虚拟化项目。也许你有一个proplem那里。分析WPF应用程序,我可以推荐你的 WPF分析工具的。

Try to look if you have something in your UI that hinders the DataGrid to virtualize the Items. Maybe you have a proplem there. To analyse WPF apps, I can recommend you the WPF Profiling Tools.