I have a simple application which performs a search in the user's computer and then display's the results. I have a function search
which searches for the files in the computer and a function DisplayForm
which then display's the form containing the results. The results are displayed inside a ListBox
.
Search function is called inside a BackgroundWorker
and the DisplayFunction
is called when the BackgroundWorker
completes.
The problem that I am facing is thate the first time the search function is called just after computer reboot , although the search function takes very less time (1 second or so), the time taken to display the form takes too long.(10 seconds or so).
Correct me if I am wrong,
based on what I have googled and read, I think the problem is that as soon as the BackgroundWorker
completes, Assemblies required for DisplayForm
start loading, which takes considerable time, and after that the form containing the search results is displayed.
I think the solution for the problem is that I can preload all the assemblies, so that when the DisplayForm
function is called, there is not time wasted in loading the assemblies.
I am completely new to this stuff, and don't have any clue on how to do it.
I know about the System.Reflection.Assembly.Load()
function, but I am unable to find "How to use it". So, basically I need help with using the Assembly.Load()
function.
Below I am posting the code for DisplayForm
function. Please have a look at it.
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();
}