解决方案 »

  1.   

    我觉得把2000个条目加入listbox本身就有问题,还有就是从最后一个开始反向删除速度会快些
      

  2.   

    原因找到了,查看中间代码才看到
    原来是listbox设计的Add与RemoveAt的方法效率有区别,具体请看下列方法,同时也需求解决方案。
    public object Add(object item)
    {
        this.EnsureSpace(1);
        this.version++;
        this.entries[this.count] = new Entry(item);
        return this.entries[this.count++];
    }public void RemoveAt(int index)
    {
        this.count--;
        for (int i = index; i < this.count; i++)
        {
            this.entries[i] = this.entries[i + 1];
        }
        this.entries[this.count] = null;
        this.version++;
    }
     寻求解决效率问题的方案。
      

  3.   

    先把循环里的 Application.DoEvents() ;  去掉。
      

  4.   

    List<Stirng> tmp = new List<Stirng>();
    tmp.AddRange(listBox.Items);
    listBox.Items.Clear();
    listBox.Items.AddRange(tmp.GetRange(100, tmp.Count - 100));
      

  5.   

    反过来做, 新建一个空的LIST, 再把满足条件的加进去。 然后控件绑定新建的LIST删除的时候移位操作因为是必须, 所以无法提升效率
      

  6.   


    我的程序是多线程并跨线程访问的,用List或ArrayList不是线程安全的,程序会出问题。
    应该有更有效率的操作方法。移位操作确实是一个“缺陷”。
      

  7.   

    经过今天的努力,终于提高了效率,现在我就把提高效率的方法打出来。
    首先建立List<string> todo=new List<string>();将数据加入todo里,然后使用数据绑定。listBox1.DataSource = null;
    listBox1.DataSource = todo;修改todo的时候最好进行lock锁定。lock (todo)
     {
            string str = todo[0];
            todo.RemoveAt(0);
     }
    效率提高了很多很多