在C#中向ListView添加项目太慢

Hun*_*uan 5 c# listview winforms

我想将项目添加到listview控件.这是一些代码:

    this.lView.ListViewItemSorter = null;
    ListViewItem[] lvitems = new ListViewItem[ListMyObjects.Count];
    int index = 0;
    foreach (MyObject object in ListMyObjects)
        {
            ListViewItem item = new ListViewItem();               
            item.Text = object.Name;
            lvitems[index++] = item;
        }
    this.lView.BeginUpdate();
    this.lView.Items.AddRange(lvitems); // Slow in here with debugger
    this.lView.EndUpdate();
Run Code Online (Sandbox Code Playgroud)

我只添加了大约1000个项目,但速度非常慢.它花了大约15秒完成.为什么有人知道原因?预先感谢.

编辑:

我以前定制过listview.

public partial class MyListView: ListView
{        
    public MyListView()
    {
        InitializeComponent();
        this.View = View.Details;
        this.FullRowSelect = true;
        this.DoubleBuffered = true;
    }
    private bool mCreating;
    private bool mReadOnly;
    protected override void OnHandleCreated(EventArgs e)
    {
        mCreating = true;
        base.OnHandleCreated(e);
        mCreating = false;
    }
    public bool ReadOnly
    {
        get { return mReadOnly; }
        set { mReadOnly = value; }
    }
    protected override void OnItemCheck(ItemCheckEventArgs e)
    {
        if (!mCreating && mReadOnly) e.NewValue = e.CurrentValue;
        base.OnItemCheck(e);
    }   
}
Run Code Online (Sandbox Code Playgroud)

我这样做是因为当我使用多个线程时我不想挂起.我不知道这会对它产生什么影响?