<small id='fS5XE'></small><noframes id='fS5XE'>

        <legend id='fS5XE'><style id='fS5XE'><dir id='fS5XE'><q id='fS5XE'></q></dir></style></legend>
        <tfoot id='fS5XE'></tfoot>
          <bdo id='fS5XE'></bdo><ul id='fS5XE'></ul>
      1. <i id='fS5XE'><tr id='fS5XE'><dt id='fS5XE'><q id='fS5XE'><span id='fS5XE'><b id='fS5XE'><form id='fS5XE'><ins id='fS5XE'></ins><ul id='fS5XE'></ul><sub id='fS5XE'></sub></form><legend id='fS5XE'></legend><bdo id='fS5XE'><pre id='fS5XE'><center id='fS5XE'></center></pre></bdo></b><th id='fS5XE'></th></span></q></dt></tr></i><div id='fS5XE'><tfoot id='fS5XE'></tfoot><dl id='fS5XE'><fieldset id='fS5XE'></fieldset></dl></div>

        使用 ListBox 缓慢显示/绘制对话?

        时间:2023-10-07

            1. <tfoot id='I6pWH'></tfoot>

                <small id='I6pWH'></small><noframes id='I6pWH'>

                <i id='I6pWH'><tr id='I6pWH'><dt id='I6pWH'><q id='I6pWH'><span id='I6pWH'><b id='I6pWH'><form id='I6pWH'><ins id='I6pWH'></ins><ul id='I6pWH'></ul><sub id='I6pWH'></sub></form><legend id='I6pWH'></legend><bdo id='I6pWH'><pre id='I6pWH'><center id='I6pWH'></center></pre></bdo></b><th id='I6pWH'></th></span></q></dt></tr></i><div id='I6pWH'><tfoot id='I6pWH'></tfoot><dl id='I6pWH'><fieldset id='I6pWH'></fieldset></dl></div>
                  <tbody id='I6pWH'></tbody>
                • <bdo id='I6pWH'></bdo><ul id='I6pWH'></ul>

                  <legend id='I6pWH'><style id='I6pWH'><dir id='I6pWH'><q id='I6pWH'></q></dir></style></legend>

                  本文介绍了使用 ListBox 缓慢显示/绘制对话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我的应用程序使用实体框架来提取一小部分结果......它需要大约 3 秒才能完成?为什么会这样?

                  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

                  ...
                  private void projectToolStripMenuItem_Click(object sender, System.EventArgs e)
                  {
                      NewProject newProjectForm = new NewProject();
                      newProjectForm.ShowDialog(); // It seems to take about 3 or 4 seconds to actually get to this :S
                  }
                  ...
                  

                  NewProject.cs

                  public partial class NewProject : Form
                  {
                      private EFProjectTypeRepository projectTypeRepository;
                  
                      public NewProject()
                      {
                          projectTypeRepository = new EFProjectTypeRepository();
                  
                          InitializeComponent();
                          ListBoxProjectTypes();
                      }
                  
                      public void ListBoxProjectTypes()
                      {    
                          DateTime then = DateTime.Now;
                  
                          // PreLoadedResources.projectTypes is a preloaded resource which takes split seconds to load.
                  
                          ListBoxProjectType.Items.AddRange(PreLoadedResources.projectTypes.Select(item => (object)item.Title).ToArray()); // If I comment this line out, the dialogue is almost instant @ timeTaken  {00:00:00.0010019}
                  
                          DateTime now = DateTime.Now;
                          TimeSpan timeTaken = now.Subtract(then); 
                      }
                  }
                  

                  :

                  timeTaken   {00:00:02.4261369}  System.TimeSpan
                  

                  当我第二次去展示对话时,它是即时的!

                  when I go and show the dialogue a second time, it's instant!

                  到目前为止,我的列表框显示了 1 个项目,哈哈.

                  注意事项:

                  public static class PreLoadedResources
                  {
                      public static IEnumerable<ProjectType> projectTypes;
                  }
                  

                  推荐答案

                  ListBox 必须在每次添加项目时重绘.您可以使用 Dmitry 使用 AddRange() 的方法,也可以使用 BeginUpdate()/EndUpdate() 调用来包装循环.

                  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();
                  

                  这篇关于使用 ListBox 缓慢显示/绘制对话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:具有覆盖 CreateParams 的 ListBox 不会引发项目事件 下一篇:试图了解通过会话传输列表框值/项目.

                  相关文章

                • <tfoot id='d8gWZ'></tfoot>
                • <i id='d8gWZ'><tr id='d8gWZ'><dt id='d8gWZ'><q id='d8gWZ'><span id='d8gWZ'><b id='d8gWZ'><form id='d8gWZ'><ins id='d8gWZ'></ins><ul id='d8gWZ'></ul><sub id='d8gWZ'></sub></form><legend id='d8gWZ'></legend><bdo id='d8gWZ'><pre id='d8gWZ'><center id='d8gWZ'></center></pre></bdo></b><th id='d8gWZ'></th></span></q></dt></tr></i><div id='d8gWZ'><tfoot id='d8gWZ'></tfoot><dl id='d8gWZ'><fieldset id='d8gWZ'></fieldset></dl></div>

                  <legend id='d8gWZ'><style id='d8gWZ'><dir id='d8gWZ'><q id='d8gWZ'></q></dir></style></legend>

                    <small id='d8gWZ'></small><noframes id='d8gWZ'>

                      <bdo id='d8gWZ'></bdo><ul id='d8gWZ'></ul>