My application uses entity framework to pull in a small tiny set of results... It takes about 3 seconds for it to do it? Why might this be?
Start.cs
Changing my IEnumerable to IList made a difference:
public static class PreLoadedResources
{
public static IEnumerable<ProjectType> projectTypes;
}
to
public static class PreLoadedResources
{
public static IList<ProjectType> projectTypes;
}
then in my loading (which takes a 2 second hit), I just .ToList
it instead... but now the showdialogue procedure takes split seconds.
The ListBox
has to redraw every time you add an item. You can either use Dmitry's method of using AddRange()
, or you can wrap your loop with BeginUpdate()
/EndUpdate()
calls.
ListBoxProjectType.BeginUpdate();
foreach( var projectType in projectTypes )
{
ListBoxProjectType.Items.Add(projectType.Title);
}
ListBoxProjectType.EndUpdate();
Try to replace adding individual items to listbox with AddRange
:
public void ListBoxProjectTypes()
{
IEnumerable<ProjectType> projectTypes = projectTypeRepository.ProjectTypes;
ListBoxProjectType.Items.AddRange(projectTypes.Select(item => (object)item.Title).ToArray());
}
Or simply wrap items adding with ListBoxProjectType.BeginUpdate
and ListBoxProjectType.EndUpdate
.