如何预加载所有组件?

时间:2013-11-27 04:10:54

标签: c# .net performance user-interface

我有一个简单的应用程序,它在用户的计算机上执行搜索,然后显示结果。我有一个函数search,用于搜索计算机中的文件和函数DisplayForm,然后显示包含结果的表单。结果显示在ListBox内 搜索功能在BackgroundWorker内调用,DisplayFunctionBackgroundWorker完成时调用。 我面临的问题是在计算机重新启动后第一次调用搜索功能时,尽管搜索功能花费的时间非常少(大约1秒左右),但显示表单所需的时间也会很长。(10秒)左右) 如果我错了,纠正我,
 根据我用Google搜索和阅读的内容,我认为问题在于BackgroundWorker完成后,DisplayForm所需的程序集开始加载,这需要相当长的时间,之后包含搜索的表单结果显示。
我认为问题的解决方案是我可以预加载所有程序集,以便在调用DisplayForm函数时,没有时间浪费加载程序集。 我对这些东西都是全新的,并且没有任何关于如何做到这一点的线索。 我知道System.Reflection.Assembly.Load()函数,但我找不到“如何使用它”。所以,基本上我需要帮助才能使用Assembly.Load()函数 下面我发布了DisplayForm函数的代码。请看一下。

    private void DisplayForm()
    {
        Label LabelMessage = new Label();
        LabelMessage.Text = "There are a total of " + ReaderClass.SearchList.Count.ToString() + " files and folders found with the given name. ";
        LabelMessage.Parent = SearchForm;
        LabelMessage.Left = 300;
        LabelMessage.Top = 0;
        LabelMessage.Size = new Size(800, 75);
        LabelMessage.Font = new Font("Impact", 20);
        LabelMessage.Show();
        SearchForm.Controls.Add(LabelMessage);
        SearchForm.AutoScroll = true;
        ResultListBox.Parent = SearchForm;
        ResultListBox.DataSource = null;
        ResultListBox.DataSource = ReaderClass.SearchList;
        ResultListBox.Width = 1340;
        ResultListBox.Height = 1300;
        ResultListBox.BorderStyle = BorderStyle.Fixed3D;
        ResultListBox.ScrollAlwaysVisible = true;
        ResultListBox.Left = 0;
        ResultListBox.Top = 100;
        ResultListBox.DoubleClick += OpenFile;
        ResultListBox.KeyDown += OpenFileKey;
        ResultListBox.Font = new Font("Arial", 14, FontStyle.Regular);
        notifyIcon1.BalloonTipText = "Search Completed. It took " + (ReaderClass.SearchTime.ElapsedMilliseconds / 1000.0).ToString() + " to complete the search. ";
        notifyIcon1.ShowBalloonTip(2000);
        if (ReaderClass.SearchList.Count != 0)
        {
            ResultListBox.DataSource = ReaderClass.SearchList;
            SearchForm.ShowDialog();
        }
        else
        {
            MessageBox.Show("Sorry, we couldn't find anything with this name.", "No Results", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }
        ReaderClass.SearchList.Clear();
        LabelMessage.Dispose();
    }

0 个答案:

没有答案